Class: BCDD::Data::Object

Inherits:
Object
  • Object
show all
Defined in:
lib/bcdd/ext/data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kargs) ⇒ Object

Returns a new instance of Object.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/bcdd/ext/data.rb', line 10

def initialize(**kargs)
  properties = self.class::Properties
  attributes = properties.map(kargs)

  @errors = {}
  @attributes =
    if properties.contract?
      attributes.each_with_object({}) do |(key, value), output|
        output[key] = value.valid? ? value.value : (errors[key] = value.errors)
      end
    else
      attributes.transform_values!(&:value)
    end
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



8
9
10
# File 'lib/bcdd/ext/data.rb', line 8

def attributes
  @attributes
end

#errorsObject (readonly)

Returns the value of attribute errors.



8
9
10
# File 'lib/bcdd/ext/data.rb', line 8

def errors
  @errors
end