Class: JRAW::JRawRunner

Inherits:
AntProject show all
Defined in:
lib/jraw_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 = {}) ⇒ 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 = '', 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 JRAW::AntProject

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



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

def root
  @root
end

#targetsObject (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(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/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(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, 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, options = {}, &block)
  target = Target.new(name)
  logger.debug("adding target #{name}")
  if options[:depends]
    if options[:depends].is_a? Symbol
      options[:depends] = [options[:depends]]
    end
    options[:depends].each do |dependancy|
      logger.debug "adding dependancy #{dependancy} to target #{name}"
      target.dependencies << dependancy
    end
  end
  target.block = block
  targets[name] = target
end