Class: Sphene::AttributeSet

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/sphene/attribute_set.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ AttributeSet

Returns a new instance of AttributeSet.



9
10
11
12
# File 'lib/sphene/attribute_set.rb', line 9

def initialize(model)
  @model = model
  super({})
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



7
8
9
# File 'lib/sphene/attribute_set.rb', line 7

def model
  @model
end

Class Method Details

.from(model) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/sphene/attribute_set.rb', line 14

def self.from(model)
  new(model).tap do |data|
    model.class.attributes.each do |name, options|
      data[name] = Attribute.new(name, model, **options)
    end
  end
end

Instance Method Details

#to_hashObject



22
23
24
25
26
# File 'lib/sphene/attribute_set.rb', line 22

def to_hash
  each.with_object({}) do |(name, attribute), data|
    data[name] = attribute.value
  end
end