Class: Schema::AttributeRegistry

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

Instance Method Summary collapse

Instance Method Details

#[](index) ⇒ Object



122
123
124
# File 'lib/schema/schema.rb', line 122

def [](index)
  entries[index]
end

#add(name, type, strict = nil) ⇒ Object



138
139
140
141
142
143
# File 'lib/schema/schema.rb', line 138

def add(name, type, strict=nil)
  strict ||= false
  attribute = Schema::Attribute.new(name, type, strict)
  entries << attribute
  attribute
end

#attribute(name) ⇒ Object



154
155
156
# File 'lib/schema/schema.rb', line 154

def attribute(name)
  entries.find { |entry| entry.name == name }
end

#attribute?(name) ⇒ Boolean

Returns:



158
159
160
# File 'lib/schema/schema.rb', line 158

def attribute?(name)
  !attribute(name).nil?
end

#each(&action) ⇒ Object



130
131
132
# File 'lib/schema/schema.rb', line 130

def each(&action)
  entries.each(&action)
end

#each_with_object(obj, &action) ⇒ Object



134
135
136
# File 'lib/schema/schema.rb', line 134

def each_with_object(obj, &action)
  entries.each_with_object(obj, &action)
end

#entriesObject



113
114
115
# File 'lib/schema/schema.rb', line 113

def entries
  @entries ||= []
end

#lengthObject Also known as: count



117
118
119
# File 'lib/schema/schema.rb', line 117

def length
  entries.length
end

#map(&action) ⇒ Object



126
127
128
# File 'lib/schema/schema.rb', line 126

def map(&action)
  entries.map(&action)
end

#register(name, type, strict = nil) ⇒ Object



145
146
147
148
# File 'lib/schema/schema.rb', line 145

def register(name, type, strict=nil)
  remove(name)
  add(name, type, strict)
end

#remove(name) ⇒ Object



150
151
152
# File 'lib/schema/schema.rb', line 150

def remove(name)
  entries.delete_if { |entry| entry.name == name }
end