Class: Schema::AttributeRegistry

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

Instance Method Summary collapse

Instance Method Details

#[](index) ⇒ Object



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

def [](index)
  entries[index]
end

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



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

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

#attribute(name) ⇒ Object



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

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

#attribute?(name) ⇒ Boolean

Returns:



143
144
145
# File 'lib/schema/schema.rb', line 143

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

#each(&action) ⇒ Object



115
116
117
# File 'lib/schema/schema.rb', line 115

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

#each_with_object(obj, &action) ⇒ Object



119
120
121
# File 'lib/schema/schema.rb', line 119

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

#entriesObject



98
99
100
# File 'lib/schema/schema.rb', line 98

def entries
  @entries ||= []
end

#lengthObject Also known as: count



102
103
104
# File 'lib/schema/schema.rb', line 102

def length
  entries.length
end

#map(&action) ⇒ Object



111
112
113
# File 'lib/schema/schema.rb', line 111

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

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



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

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

#remove(name) ⇒ Object



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

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