Class: Sprout::Executable::FileParam

Inherits:
Param
  • Object
show all
Defined in:
sprout/lib/sprout/executable/file_param.rb

Overview

Concrete Sprout::Executable::Param object for File values.

This class is used in Sprout::Excecutable s with:

add_param :some_name, File

This parameter is truly special in that whatever values are sent to the File parameter will be added to the underlying Rake task as prerequisites and must exist before Sprout::Executable.execute is called - unless the parameter value matches the Sprout::Executable instance's output value.

Of course this will only be the case if there is a Rake task wrapper for the Executable, if the Sprout::Executable is being used to create a Ruby executable, then these File parameters will only be validated before execution.

See Also:

Constant Summary

Constants inherited from Param

DEFAULT_DELIMITER, DEFAULT_OPTION_PARSER_TYPE_NAME, DEFAULT_PREFIX, DEFAULT_SHORT_PREFIX

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Param

#clean_path, #default, #default=, #default_option_parser_declaration, #file_is_output?, #hidden_name?, #hidden_value?, #option_parser_declaration, #option_parser_name, #option_parser_short_name, #option_parser_type_name, #option_parser_type_output, #prepare, #prepared?, #required?, #short_prefix, #to_rdoc, #to_shell, #visible?

Constructor Details

- (FileParam) initialize

A new instance of FileParam



29
30
31
32
# File 'sprout/lib/sprout/executable/file_param.rb', line 29

def initialize
  super
  @option_parser_type_name = 'FILE'
end

Instance Attribute Details

- (Object) file_task_name

Returns the value of attribute file_task_name



27
28
29
# File 'sprout/lib/sprout/executable/file_param.rb', line 27

def file_task_name
  @file_task_name
end

Instance Method Details

- (Object) prepare_prerequisites



38
39
40
41
42
43
44
45
46
47
48
# File 'sprout/lib/sprout/executable/file_param.rb', line 38

def prepare_prerequisites
  if file_task_name
    self.value ||= belongs_to.rake_task_name
    return
  end

  if prerequisite?(value)
    file value
    belongs_to.prerequisites << value
  end
end

- (Object) shell_value



34
35
36
# File 'sprout/lib/sprout/executable/file_param.rb', line 34

def shell_value
  clean_path value
end

- (Object) validate



50
51
52
53
54
55
56
# File 'sprout/lib/sprout/executable/file_param.rb', line 50

def validate
  super

  if(!file_task_name && !value.nil? && !File.exists?(value))
    raise Sprout::Errors::InvalidArgumentError.new "No such file or directory - #{value}"
  end
end