Class: Schema::AttributeRegistry
- Inherits:
-
Object
- Object
- Schema::AttributeRegistry
- Defined in:
- lib/schema/schema.rb
Instance Method Summary collapse
- #[](index) ⇒ Object
- #add(name, type, strict = nil) ⇒ 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, strict = nil) ⇒ Object
- #remove(name) ⇒ Object
Instance Method Details
#[](index) ⇒ Object
121 122 123 |
# File 'lib/schema/schema.rb', line 121 def [](index) entries[index] end |
#add(name, type, strict = nil) ⇒ Object
137 138 139 140 141 142 |
# File 'lib/schema/schema.rb', line 137 def add(name, type, strict=nil) strict ||= false attribute = Schema::Attribute.new(name, type, strict) entries << attribute attribute end |
#attribute(name) ⇒ Object
153 154 155 |
# File 'lib/schema/schema.rb', line 153 def attribute(name) entries.find { |entry| entry.name == name } end |
#attribute?(name) ⇒ Boolean
157 158 159 |
# File 'lib/schema/schema.rb', line 157 def attribute?(name) !attribute(name).nil? end |
#each(&action) ⇒ Object
129 130 131 |
# File 'lib/schema/schema.rb', line 129 def each(&action) entries.each(&action) end |
#each_with_object(obj, &action) ⇒ Object
133 134 135 |
# File 'lib/schema/schema.rb', line 133 def each_with_object(obj, &action) entries.each_with_object(obj, &action) end |
#entries ⇒ Object
112 113 114 |
# File 'lib/schema/schema.rb', line 112 def entries @entries ||= [] end |
#length ⇒ Object Also known as: count
116 117 118 |
# File 'lib/schema/schema.rb', line 116 def length entries.length end |
#map(&action) ⇒ Object
125 126 127 |
# File 'lib/schema/schema.rb', line 125 def map(&action) entries.map(&action) end |
#register(name, type, strict = nil) ⇒ Object
144 145 146 147 |
# File 'lib/schema/schema.rb', line 144 def register(name, type, strict=nil) remove(name) add(name, type, strict) end |
#remove(name) ⇒ Object
149 150 151 |
# File 'lib/schema/schema.rb', line 149 def remove(name) entries.delete_if { |entry| entry.name == name } end |