Class: ActiveInteractor::Context::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/active_interactor/context/result.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Result

Returns a new instance of Result.



19
20
21
22
23
24
25
# File 'lib/active_interactor/context/result.rb', line 19

def initialize(attributes = {})
  @attributes = {}
  attributes.each_pair do |key, value|
    instance_variable_set(:"@#{key}", value)
    @attributes[key] = value
  end
end

Class Method Details

.for_output_context(owner, context) ⇒ Object



14
15
16
17
# File 'lib/active_interactor/context/result.rb', line 14

def self.for_output_context(owner, context)
  context.fields.each_key { |field| owner::ResultContext.send(:attr_reader, field) }
  owner::ResultContext.new(context.fields.deep_dup)
end

.register_owner(owner) ⇒ Object



10
11
12
# File 'lib/active_interactor/context/result.rb', line 10

def self.register_owner(owner)
  owner.const_set(:ResultContext, Class.new(self))
end

Instance Method Details

#[](*args, &block) ⇒ Object



6
7
8
# File 'lib/active_interactor/context/result.rb', line 6

def [](*args, &block)
  to_hash.[](*args, &block)
end

#as_json(*args, &block) ⇒ Object



7
8
9
# File 'lib/active_interactor/context/result.rb', line 7

def as_json(*args, &block)
  to_hash.as_json(*args, &block)
end

#to_hashObject Also known as: to_h



27
28
29
# File 'lib/active_interactor/context/result.rb', line 27

def to_hash
  @attributes.with_indifferent_access
end

#to_json(*args, &block) ⇒ Object



8
9
10
# File 'lib/active_interactor/context/result.rb', line 8

def to_json(*args, &block)
  to_hash.to_json(*args, &block)
end