Class: RAW::RawRunner

Inherits:
AntProject show all
Defined in:
lib/raw_runner.rb

Instance Attribute Summary collapse

Attributes inherited from AntProject

#ant_version, #declarative, #default_target, #logger, #project

Instance Method Summary collapse

Methods inherited from AntProject

#basedir, #build_instance_variable, #build_properties, #init_project, #instvar, #method_missing, #name, #property_value, #to_s

Constructor Details

#initialize(template, root = '', options = {}) ⇒ RawRunner

Returns a new instance of RawRunner.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/raw_runner.rb', line 24

def initialize(template, root = '', options = {})
  super(options)
  @targets = Hash.new
  @root = File.expand_path(File.directory?(root) ? root : File.join(Dir.pwd, root))

  if template
    logger.info("Applying script #{template}")

    load_script(template)

    # Execute the given target
    if options[:target]
      build options[:target]
    # or find the default and call that 
    elsif @default_target
      build @default_target.to_sym
    end

    logger.info"Applied script #{template}"
  else
    logger.info"No script #{template} applied."
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RAW::AntProject

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



22
23
24
# File 'lib/raw_runner.rb', line 22

def root
  @root
end

#targetsObject (readonly)

Returns the value of attribute targets.



22
23
24
# File 'lib/raw_runner.rb', line 22

def targets
  @targets
end

Instance Method Details

#build(task) ⇒ Object



97
98
99
100
101
# File 'lib/raw_runner.rb', line 97

def build(task)
  block = targets[task]
  raise "No target named #{task} found." unless block
  block.call
end

#condition(options) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/raw_runner.rb', line 66

def condition(options)
  property = options[:property]
  environment = options[:value]


  if name
    build_instance_variable([name, options[:location] || options[:value]])
  elsif file || environment
    build_properties
  else
    logger.debug options.inspect
    raise "No name or file attribute given for property!"
  end
  method_missing(:property, options)
end

#load_script(template) ⇒ Object



83
84
85
86
87
88
89
90
91
# File 'lib/raw_runner.rb', line 83

def load_script(template)
  begin
    code = open(template).read

    self.instance_eval(code)
  rescue LoadError, Errno::ENOENT => e
    raise "The script #{template} could not be loaded. Error: #{e}"
  end
end

#property(options) ⇒ Object

defines a property in ant and also an instance variable



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/raw_runner.rb', line 49

def property(options)
  name = options[:name]
  file = options[:file]
  environment = options[:environment]

  method_missing(:property, options)

  if name
    build_instance_variable([name, options[:location] || options[:value]])
  elsif file || environment
    build_properties
  else
    logger.debug options.inspect
    raise "No name or file attribute given for property!"
  end
end

#target(name, depends = [], &block) ⇒ Object



93
94
95
# File 'lib/raw_runner.rb', line 93

def target(name, depends = [], &block)
  targets[name] = block
end