Class: Evil::Client::Model
- Inherits:
-
Object
- Object
- Evil::Client::Model
- Extended by:
- Dry::Initializer::Mixin
- Defined in:
- lib/evil/client/model.rb
Class Method Summary collapse
- .call(value) ⇒ Object (also: [])
- .new(value) ⇒ Object
Instance Method Summary collapse
Class Method Details
.call(value) ⇒ Object Also known as: []
24 25 26 |
# File 'lib/evil/client/model.rb', line 24 def call(value) new(value).to_h end |
.new(value) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/evil/client/model.rb', line 16 def new(value) return value if value.is_a? self value = value.to_h.each_with_object({}) do |(key, val), obj| obj[key.to_sym] = val end super value end |
Instance Method Details
#==(other) ⇒ Object
32 33 34 35 |
# File 'lib/evil/client/model.rb', line 32 def ==(other) return false unless other.respond_to? :to_h to_h == other.to_h end |
#to_h ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/evil/client/model.rb', line 37 def to_h attributes = method(:initialize) .parameters .map { |item| item[1] unless item[0] == :keyrest } .compact attributes.each_with_object({}) do |key, hash| val = send(key) hash[key] = hashify(val) unless val == Dry::Initializer::UNDEFINED end end |