Class: LittleMonster::Core::Job::Data
- Inherits:
-
Object
- Object
- LittleMonster::Core::Job::Data
- Defined in:
- lib/little_monster/core/job_data.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](output_key) ⇒ Object
- #[]=(output_key, value) ⇒ Object
-
#initialize(job, input = {}) ⇒ Data
constructor
A new instance of Data.
- #length ⇒ Object
- #to_h ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(job, input = {}) ⇒ Data
Returns a new instance of Data.
3 4 5 6 7 |
# File 'lib/little_monster/core/job_data.rb', line 3 def initialize(job, input = {}) @outputs = input.fetch(:outputs, {}) @key_owners = input.fetch(:owners, {}) @job = job end |
Instance Method Details
#==(other) ⇒ Object
9 10 11 12 13 |
# File 'lib/little_monster/core/job_data.rb', line 9 def ==(other) return false unless is_valid?(other) && other.length == length @outputs.each { |k, v| return false unless other[k.to_sym] == v } true end |
#[](output_key) ⇒ Object
15 16 17 |
# File 'lib/little_monster/core/job_data.rb', line 15 def [](output_key) @outputs[output_key.to_sym] end |
#[]=(output_key, value) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/little_monster/core/job_data.rb', line 19 def []=(output_key, value) raise KeyError, "The key #{output_key} already exists" if @outputs.include? output_key.to_sym @outputs[output_key.to_sym] = value owner = @job.current_action.to_sym @key_owners[owner] = [] unless @key_owners[owner].is_a? Array @key_owners[owner] << output_key.to_sym end |
#length ⇒ Object
37 38 39 |
# File 'lib/little_monster/core/job_data.rb', line 37 def length @outputs.length end |
#to_h ⇒ Object
32 33 34 35 |
# File 'lib/little_monster/core/job_data.rb', line 32 def to_h return {} if @outputs.empty? { outputs: @outputs, owners: @key_owners } end |
#to_json ⇒ Object
28 29 30 |
# File 'lib/little_monster/core/job_data.rb', line 28 def to_json MultiJson.dump(to_h) end |