Class: Schema::AttributeRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/schema/schema.rb

Instance Method Summary collapse

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

Returns:



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

#entriesObject



106
107
108
# File 'lib/schema/schema.rb', line 106

def entries
  @entries ||= []
end

#lengthObject 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