Class: Mongar::Column
- Inherits:
-
Object
- Object
- Mongar::Column
- Defined in:
- lib/mongar/column.rb
Instance Attribute Summary collapse
-
#is_indexed ⇒ Object
Returns the value of attribute is_indexed.
-
#is_primary_index ⇒ Object
Returns the value of attribute is_primary_index.
-
#name ⇒ Object
Returns the value of attribute name.
-
#transformation ⇒ Object
Returns the value of attribute transformation.
Instance Method Summary collapse
- #index ⇒ Object
- #indexed? ⇒ Boolean
-
#initialize(args = {}) ⇒ Column
constructor
A new instance of Column.
- #primary_index ⇒ Object
- #primary_index? ⇒ Boolean
- #transform(proc_name = nil, &block) ⇒ Object
- #transform_this(object) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Column
Returns a new instance of Column.
5 6 7 8 9 10 |
# File 'lib/mongar/column.rb', line 5 def initialize(args = {}) self.name = args[:name] self.transformation = nil self.is_indexed = false self.is_primary_index = false end |
Instance Attribute Details
#is_indexed ⇒ Object
Returns the value of attribute is_indexed.
3 4 5 |
# File 'lib/mongar/column.rb', line 3 def is_indexed @is_indexed end |
#is_primary_index ⇒ Object
Returns the value of attribute is_primary_index.
3 4 5 |
# File 'lib/mongar/column.rb', line 3 def is_primary_index @is_primary_index end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/mongar/column.rb', line 3 def name @name end |
#transformation ⇒ Object
Returns the value of attribute transformation.
3 4 5 |
# File 'lib/mongar/column.rb', line 3 def transformation @transformation end |
Instance Method Details
#index ⇒ Object
26 27 28 |
# File 'lib/mongar/column.rb', line 26 def index self.is_indexed = true end |
#indexed? ⇒ Boolean
34 35 36 |
# File 'lib/mongar/column.rb', line 34 def indexed? self.is_indexed end |
#primary_index ⇒ Object
30 31 32 |
# File 'lib/mongar/column.rb', line 30 def primary_index self.is_primary_index = true end |
#primary_index? ⇒ Boolean
38 39 40 |
# File 'lib/mongar/column.rb', line 38 def primary_index? self.is_primary_index end |
#transform(proc_name = nil, &block) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/mongar/column.rb', line 12 def transform(proc_name = nil, &block) self.transformation = lambda do result = self result = instance_exec(result, &block) if block_given? result = result.send(proc_name) if proc_name result end end |
#transform_this(object) ⇒ Object
21 22 23 24 |
# File 'lib/mongar/column.rb', line 21 def transform_this(object) return object unless transformation && transformation.is_a?(Proc) object.instance_exec(&transformation) end |