Class: JRAW::JRawRunner
- Inherits:
-
AntProject
- Object
- AntProject
- JRAW::JRawRunner
- Defined in:
- lib/jraw_runner.rb
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#targets ⇒ Object
readonly
Returns the value of attribute targets.
Attributes inherited from AntProject
#ant_version, #declarative, #default_target, #logger, #project
Instance Method Summary collapse
- #build(task) ⇒ Object
- #condition(options) ⇒ Object
-
#initialize(template, root = '', options = {}) ⇒ JRawRunner
constructor
A new instance of JRawRunner.
- #load_script(template) ⇒ Object
-
#property(options) ⇒ Object
defines a property in ant and also an instance variable.
- #target(name, options = {}, &block) ⇒ Object
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 = {}) ⇒ JRawRunner
Returns a new instance of JRawRunner.
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/jraw_runner.rb', line 24 def initialize(template, root = '', = {}) super() @targets = Hash.new @root = File.(File.directory?(root) ? root : File.join(Dir.pwd, root)) if template logger.info("Applying script #{template}") load_script(template) # Execute the given target if [:target] build [: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 JRAW::AntProject
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
22 23 24 |
# File 'lib/jraw_runner.rb', line 22 def root @root end |
#targets ⇒ Object (readonly)
Returns the value of attribute targets.
22 23 24 |
# File 'lib/jraw_runner.rb', line 22 def targets @targets end |
Instance Method Details
#build(task) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/jraw_runner.rb', line 109 def build(task) block = nil block = targets[task].block if targets[task] raise "No target named #{task} found." unless block targets[task].dependencies.each do |dependency| logger.debug("But calling target #{dependency} before") build dependency end logger.info("Calling target #{task}") block.call end |
#condition(options) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/jraw_runner.rb', line 66 def condition() property = [:property] environment = [:value] if name build_instance_variable([name, [:location] || [:value]]) elsif file || environment build_properties else logger.debug .inspect raise "No name or file attribute given for property!" end method_missing(:property, ) end |
#load_script(template) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/jraw_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/jraw_runner.rb', line 49 def property() name = [:name] file = [:file] environment = [:environment] method_missing(:property, ) if name build_instance_variable([name, [:location] || [:value]]) elsif file || environment build_properties else logger.debug .inspect raise "No name or file attribute given for property!" end end |
#target(name, options = {}, &block) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/jraw_runner.rb', line 93 def target(name, = {}, &block) target = Target.new(name) logger.debug("adding target #{name}") if [:depends] if [:depends].is_a? Symbol [:depends] = [[:depends]] end [:depends].each do |dependancy| logger.debug "adding dependancy #{dependancy} to target #{name}" target.dependencies << dependancy end end target.block = block targets[name] = target end |