class LittleMonster::Core::Job::Data
Public Class Methods
new(job, input = {})
click to toggle source
# 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
Public Instance Methods
==(other)
click to toggle source
# 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)
click to toggle source
# File lib/little_monster/core/job_data.rb, line 15 def [](output_key) @outputs[output_key.to_sym] end
[]=(output_key, value)
click to toggle source
# 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()
click to toggle source
# File lib/little_monster/core/job_data.rb, line 37 def length @outputs.length end
to_h()
click to toggle source
# 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()
click to toggle source
# File lib/little_monster/core/job_data.rb, line 28 def to_json MultiJson.dump(to_h) end
Private Instance Methods
is_valid?(other)
click to toggle source
# File lib/little_monster/core/job_data.rb, line 43 def is_valid?(other) other.instance_of?(Job::Data) || other.instance_of?(Hash) end