Class: Mongar::Column

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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_indexedObject

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_indexObject

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

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/mongar/column.rb', line 3

def name
  @name
end

#transformationObject

Returns the value of attribute transformation.



3
4
5
# File 'lib/mongar/column.rb', line 3

def transformation
  @transformation
end

Instance Method Details

#indexObject



26
27
28
# File 'lib/mongar/column.rb', line 26

def index
  self.is_indexed = true
end

#indexed?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/mongar/column.rb', line 34

def indexed?
  self.is_indexed
end

#primary_indexObject



30
31
32
# File 'lib/mongar/column.rb', line 30

def primary_index
  self.is_primary_index = true
end

#primary_index?Boolean

Returns:

  • (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