Class: Bricolage::JobClass
- Inherits:
-
Object
- Object
- Bricolage::JobClass
- Defined in:
- lib/bricolage/jobclass.rb
Constant Summary collapse
- CLASSES =
{}
- LOAD_PATH =
[srcdir + 'jobclass']
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
- #declarations(&block) ⇒ Object
- #get_declarations(params) ⇒ Object
- #get_parameters ⇒ Object
- #get_script(params) ⇒ Object
-
#initialize(id) ⇒ JobClass
constructor
A new instance of JobClass.
- #inspect ⇒ Object
- #invoke_parameters_filter(job) ⇒ Object
- #parameters(&block) ⇒ Object
- #parameters_filter(&block) ⇒ Object
- #script(&block) ⇒ Object
Constructor Details
#initialize(id) ⇒ JobClass
Returns a new instance of JobClass.
47 48 49 50 51 52 53 |
# File 'lib/bricolage/jobclass.rb', line 47 def initialize(id) @id = id @parameters = nil @parameters_filter = nil # optional @declarations = nil @script = nil end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
55 56 57 |
# File 'lib/bricolage/jobclass.rb', line 55 def id @id end |
Class Method Details
.define(id, &block) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/bricolage/jobclass.rb', line 12 def JobClass.define(id, &block) id = id.to_s raise FatalError, "duplicated job class: #{@id.inspect}" if CLASSES[id] c = new(id) c.instance_exec(c, &block) CLASSES[id] = c end |
.each(&block) ⇒ Object
43 44 45 |
# File 'lib/bricolage/jobclass.rb', line 43 def JobClass.each(&block) CLASSES.each_value(&block) end |
.get(id) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bricolage/jobclass.rb', line 23 def JobClass.get(id) unless CLASSES[id.to_s] begin path = LOAD_PATH.map {|prefix| prefix + "#{id}.rb" }.detect(&:exist?) raise ParameterError, "no such job class: #{id}" unless path ::Bricolage.module_eval File.read(path), path.to_path, 1 rescue SystemCallError => err raise FatalError, "could not load job class: #{id}: #{err.}" end raise FatalError, "job class file loaded but required job class is not defined: #{id}" unless CLASSES[id.to_s] end CLASSES[id.to_s] end |
Instance Method Details
#declarations(&block) ⇒ Object
79 80 81 |
# File 'lib/bricolage/jobclass.rb', line 79 def declarations(&block) @declarations = block end |
#get_declarations(params) ⇒ Object
83 84 85 |
# File 'lib/bricolage/jobclass.rb', line 83 def get_declarations(params) @declarations ? @declarations.call(params) : Declarations.new end |
#get_parameters ⇒ Object
65 66 67 68 69 |
# File 'lib/bricolage/jobclass.rb', line 65 def get_parameters Parameters::Declarations.new.tap {|params| @parameters.call(params) } end |
#get_script(params) ⇒ Object
91 92 93 94 95 |
# File 'lib/bricolage/jobclass.rb', line 91 def get_script(params) Script.new.tap {|script| @script.call(params, script) } end |
#inspect ⇒ Object
57 58 59 |
# File 'lib/bricolage/jobclass.rb', line 57 def inspect "\#<#{self.class} #{@id}>" end |
#invoke_parameters_filter(job) ⇒ Object
75 76 77 |
# File 'lib/bricolage/jobclass.rb', line 75 def invoke_parameters_filter(job) @parameters_filter.call(job) if @parameters_filter end |
#parameters(&block) ⇒ Object
61 62 63 |
# File 'lib/bricolage/jobclass.rb', line 61 def parameters(&block) @parameters = block end |
#parameters_filter(&block) ⇒ Object
71 72 73 |
# File 'lib/bricolage/jobclass.rb', line 71 def parameters_filter(&block) @parameters_filter = block end |
#script(&block) ⇒ Object
87 88 89 |
# File 'lib/bricolage/jobclass.rb', line 87 def script(&block) @script = block end |