Class: Scheming::Attribute::List
- Inherits:
-
Object
- Object
- Scheming::Attribute::List
show all
- Includes:
- Enumerable
- Defined in:
- lib/scheming/attribute/list.rb
Overview
Defined Under Namespace
Classes: MissingAttribute
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attributes = []) ⇒ List
Returns a new instance of List.
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/scheming/attribute/list.rb', line 13
def initialize(attributes = [])
@attributes = attributes.uniq(&:field_name).freeze
@lookup =
@attributes
.each_with_object({}) do |attr, lookup|
lookup[attr.field_name] = attr
end
.freeze
freeze
end
|
Class Method Details
10
|
# File 'lib/scheming/attribute/list.rb', line 10
def self.empty = @empty ||= new([])
|
Instance Method Details
28
29
30
31
32
33
34
35
36
|
# File 'lib/scheming/attribute/list.rb', line 28
def attr(key)
@lookup.fetch(key) do |attr_key|
raise MissingAttribute, " Missing Attribute [\#{attr_key}]\n Available Fields:\n \#{@attributes.map(&:field_name).join(\"\\n \")}\n MSG\n end\nend\n".strip!
|
#each {|| ... } ⇒ Object
46
47
48
49
50
|
# File 'lib/scheming/attribute/list.rb', line 46
def each(&)
return enum_for(:each) unless block_given?
@attributes.each(&)
end
|
#required ⇒ Object
39
|
# File 'lib/scheming/attribute/list.rb', line 39
def required = each.select(&:is_required)
|
42
|
# File 'lib/scheming/attribute/list.rb', line 42
def to_h = @lookup
|