Class: Ivy::Target

Inherits:
Object
  • Object
show all
Defined in:
lib/ivy/target.rb

Overview

Base class with general logic to call a Ivy ant target

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ant, cache_dir = nil) ⇒ Target

Returns a new instance of Target.



15
16
17
18
19
# File 'lib/ivy/target.rb', line 15

def initialize(ant, cache_dir = nil)
  raise "Cache result directory does not exists '#{cache_dir}'" if cache_dir != nil && !File.directory?(cache_dir)
  @ant = ant
  @cache_dir = cache_dir
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



13
14
15
# File 'lib/ivy/target.rb', line 13

def params
  @params
end

Instance Method Details

#execute(*params) ⇒ Object

Executes this ivy target with given parameters returning a result. __params__ can be a single Hash or an Array with or without a Hash as last value. every value in array will be converted to string and set to __true__.

I.e. [:force, 'validate', {'name' => 'Blub'}] results in parameters {'force'=>true, 'validate' => true, 'name'=>'Blub'}



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ivy/target.rb', line 27

def execute(*params)
  @params = {}
  params.pop.each { |key, value| @params[key] = value } if Hash === params.last
  params.each { |key| @params[key.to_s] = true }
  if caching_enabled? && File.exists?(cache_file_path)
    load_from_yaml
  else
    result = execute_target
    dump_to_yaml(result) if caching_enabled?
    result
  end
end