Class: ABBYY::Cloud::Model

Inherits:
Object
  • Object
show all
Extended by:
Dry::Initializer::Mixin
Defined in:
lib/abbyy/cloud/model.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.attributesObject



25
26
27
# File 'lib/abbyy/cloud/model.rb', line 25

def attributes
  @attributes ||= []
end

.new(value) ⇒ Object Also known as: call, []



14
15
16
17
18
19
20
21
# File 'lib/abbyy/cloud/model.rb', line 14

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

.option(name, type = nil, as: nil, **opts) ⇒ Object Also known as: attribute, param



29
30
31
# File 'lib/abbyy/cloud/model.rb', line 29

def option(name, type = nil, as: nil, **opts)
  super.tap { attributes << (as || name).to_sym }
end

Instance Method Details

#==(other) ⇒ Object



43
44
45
# File 'lib/abbyy/cloud/model.rb', line 43

def ==(other)
  other.respond_to?(:to_h) ? to_h == other.to_h : false
end

#to_hObject



47
48
49
50
51
52
# File 'lib/abbyy/cloud/model.rb', line 47

def to_h
  self.class.attributes.each_with_object({}) do |key, hash|
    val = send(key)
    hash[key] = hashify(val) unless val == Dry::Initializer::UNDEFINED
  end
end