Class: Amsi::Model::Base::AttributeStore

Inherits:
Object
  • Object
show all
Defined in:
lib/amsi/model/base/attribute_store.rb

Overview

Hold attributes defined with the DSL in Models

Instance Method Summary collapse

Constructor Details

#initialize(model_class) ⇒ AttributeStore

Returns a new instance of AttributeStore.



8
9
10
11
# File 'lib/amsi/model/base/attribute_store.rb', line 8

def initialize(model_class)
  @model_class = model_class
  @attributes = []
end

Instance Method Details

#add(type, attrs) ⇒ Object

Add all attributes of the same type to the AttributeStore



14
15
16
17
18
19
20
# File 'lib/amsi/model/base/attribute_store.rb', line 14

def add(type, attrs)
  attrs.map do |attr|
    attribute = Attribute.new(prefix: prefix, type: type, name: attr)
    @attributes << attribute
    attribute
  end
end

#find(attr) ⇒ Object

Find a specific attribute with the given name



23
24
25
# File 'lib/amsi/model/base/attribute_store.rb', line 23

def find(attr)
  attributes.detect { |attribute| attribute.matches?(attr) }
end