Class: Schema::AttributeRegistry

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

Instance Method Summary collapse

Instance Method Details

#[](index) ⇒ Object



93
94
95
# File 'lib/schema/schema.rb', line 93

def [](index)
  entries[index]
end

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



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

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

#attribute(name) ⇒ Object



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

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

#attribute?(name) ⇒ Boolean

Returns:



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

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

#each(&action) ⇒ Object



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

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

#each_with_object(obj, &action) ⇒ Object



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

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

#entriesObject



84
85
86
# File 'lib/schema/schema.rb', line 84

def entries
  @entries ||= []
end

#lengthObject Also known as: count



88
89
90
# File 'lib/schema/schema.rb', line 88

def length
  entries.length
end

#map(&action) ⇒ Object



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

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

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



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

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

#remove(name) ⇒ Object



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

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