Class: Schema::AttributeRegistry
- Inherits:
-
Object
- Object
- Schema::AttributeRegistry
- Defined in:
- lib/schema/schema.rb
Instance Method Summary collapse
- #[](index) ⇒ Object
- #add(name, type) ⇒ Object
- #attribute(name) ⇒ Object
- #attribute?(name) ⇒ Boolean
- #each(&action) ⇒ Object
- #each_with_object(obj, &action) ⇒ Object
- #entries ⇒ Object
- #length ⇒ Object (also: #count)
- #map(&action) ⇒ Object
- #register(name, type) ⇒ Object
- #remove(name) ⇒ Object
Instance Method Details
#[](index) ⇒ Object
115 116 117 |
# File 'lib/schema/schema.rb', line 115 def [](index) entries[index] end |
#add(name, type) ⇒ Object
131 132 133 134 135 |
# File 'lib/schema/schema.rb', line 131 def add(name, type) attribute = Schema::Attribute.new(name, type) entries << attribute attribute end |
#attribute(name) ⇒ Object
146 147 148 |
# File 'lib/schema/schema.rb', line 146 def attribute(name) entries.find { |entry| entry.name == name } end |
#attribute?(name) ⇒ Boolean
150 151 152 |
# File 'lib/schema/schema.rb', line 150 def attribute?(name) !attribute(name).nil? end |
#each(&action) ⇒ Object
123 124 125 |
# File 'lib/schema/schema.rb', line 123 def each(&action) entries.each(&action) end |
#each_with_object(obj, &action) ⇒ Object
127 128 129 |
# File 'lib/schema/schema.rb', line 127 def each_with_object(obj, &action) entries.each_with_object(obj, &action) end |
#entries ⇒ Object
106 107 108 |
# File 'lib/schema/schema.rb', line 106 def entries @entries ||= [] end |
#length ⇒ Object Also known as: count
110 111 112 |
# File 'lib/schema/schema.rb', line 110 def length entries.length end |
#map(&action) ⇒ Object
119 120 121 |
# File 'lib/schema/schema.rb', line 119 def map(&action) entries.map(&action) end |
#register(name, type) ⇒ Object
137 138 139 140 |
# File 'lib/schema/schema.rb', line 137 def register(name, type) remove(name) add(name, type) end |
#remove(name) ⇒ Object
142 143 144 |
# File 'lib/schema/schema.rb', line 142 def remove(name) entries.delete_if { |entry| entry.name == name } end |