Class: SimpleAdvice::Object

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/simple_advice/object.rb

Direct Known Subclasses

Advice

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Object

Returns a new instance of Object.



7
8
9
# File 'lib/simple_advice/object.rb', line 7

def initialize(attributes)
  super to_struct(attributes)
end

Instance Method Details

#to_struct(obj) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/simple_advice/object.rb', line 11

def to_struct(obj)
  case obj
  when is_a?(Hash)
    OpenStruct.new(obj.transform_values(&:to_ostruct))
  when is_a?(Array)
    obj.map { |o| to_ostruct(o) }
  else
    obj
  end
end