Class: Redpear::Schema::Collection
- Inherits:
-
Array
- Object
- Array
- Redpear::Schema::Collection
- Defined in:
- lib/redpear/schema/collection.rb
Overview
Stores the column information
Instance Method Summary collapse
-
#[](name) ⇒ Redpear::Schema::Column
The column for the given name.
-
#include?(name) ⇒ Boolean
If name is part of the collection.
-
#indicies ⇒ Array
Only the index columns.
-
#lookup ⇒ Hash
The column lookup, indexed by name.
-
#names ⇒ Array
The names of the columns.
-
#reset! ⇒ Object
Resets indexes and lookups.
- #store(klass, *args) ⇒ Object
Instance Method Details
#[](name) ⇒ Redpear::Schema::Column
Returns the column for the given name.
35 36 37 |
# File 'lib/redpear/schema/collection.rb', line 35 def [](name) lookup[name.to_s] end |
#include?(name) ⇒ Boolean
Returns if name is part of the collection.
29 30 31 |
# File 'lib/redpear/schema/collection.rb', line 29 def include?(name) lookup.key?(name.to_s) end |
#indicies ⇒ Array
Returns only the index columns.
23 24 25 |
# File 'lib/redpear/schema/collection.rb', line 23 def indicies @indicies ||= to_a.select {|i| i.is_a?(Redpear::Schema::Index) } end |
#lookup ⇒ Hash
Returns the column lookup, indexed by name.
18 19 20 |
# File 'lib/redpear/schema/collection.rb', line 18 def lookup @lookup ||= inject({}) {|r, c| r.update c.to_s => c } end |
#names ⇒ Array
Returns the names of the columns.
13 14 15 |
# File 'lib/redpear/schema/collection.rb', line 13 def names @names ||= lookup.keys end |
#reset! ⇒ Object
Resets indexes and lookups
40 41 42 43 44 |
# File 'lib/redpear/schema/collection.rb', line 40 def reset! instance_variables.each do |name| instance_variable_set name, nil end end |
#store(klass, *args) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/redpear/schema/collection.rb', line 5 def store(klass, *args) reset! klass.new(*args).tap do |col| self << col end end |