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
110 111 112 |
# File 'lib/schema/schema.rb', line 110 def [](index) entries[index] end |
#add(name, type) ⇒ Object
126 127 128 129 130 |
# File 'lib/schema/schema.rb', line 126 def add(name, type) attribute = Schema::Attribute.new(name, type) entries << attribute attribute end |
#attribute(name) ⇒ Object
141 142 143 |
# File 'lib/schema/schema.rb', line 141 def attribute(name) entries.find { |entry| entry.name == name } end |
#attribute?(name) ⇒ Boolean
145 146 147 |
# File 'lib/schema/schema.rb', line 145 def attribute?(name) !attribute(name).nil? end |
#each(&action) ⇒ Object
118 119 120 |
# File 'lib/schema/schema.rb', line 118 def each(&action) entries.each(&action) end |
#each_with_object(obj, &action) ⇒ Object
122 123 124 |
# File 'lib/schema/schema.rb', line 122 def each_with_object(obj, &action) entries.each_with_object(obj, &action) end |
#entries ⇒ Object
101 102 103 |
# File 'lib/schema/schema.rb', line 101 def entries @entries ||= [] end |
#length ⇒ Object Also known as: count
105 106 107 |
# File 'lib/schema/schema.rb', line 105 def length entries.length end |
#map(&action) ⇒ Object
114 115 116 |
# File 'lib/schema/schema.rb', line 114 def map(&action) entries.map(&action) end |
#register(name, type) ⇒ Object
132 133 134 135 |
# File 'lib/schema/schema.rb', line 132 def register(name, type) remove(name) add(name, type) end |
#remove(name) ⇒ Object
137 138 139 |
# File 'lib/schema/schema.rb', line 137 def remove(name) entries.delete_if { |entry| entry.name == name } end |