Class: Lolita::Configuration::Columns

Inherits:
Object
  • Object
show all
Includes:
Enumerable, ObservedArray
Defined in:
lib/lolita/configuration/columns.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ObservedArray

#<<, #[]=, #insert, #method_missing, #push

Constructor Details

#initialize(list, dbi = nil) ⇒ Columns

Returns a new instance of Columns.



11
12
13
14
15
# File 'lib/lolita/configuration/columns.rb', line 11

def initialize(list,dbi=nil)
  @list=list
  @dbi=dbi || list.dbi
  @columns=[]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Lolita::ObservedArray

Instance Attribute Details

#dbiObject (readonly)

Returns the value of attribute dbi.



9
10
11
# File 'lib/lolita/configuration/columns.rb', line 9

def dbi
  @dbi
end

#listObject

Returns the value of attribute list.



8
9
10
# File 'lib/lolita/configuration/columns.rb', line 8

def list
  @list
end

Instance Method Details

#add(attributes = {}, &block) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/lolita/configuration/columns.rb', line 34

def add attributes={},&block
  if block_given?
    @columns<<build_element(&block)
  else
    @columns<<build_element(attributes)
  end
  self
end

#eachObject



17
18
19
20
21
22
23
24
25
# File 'lib/lolita/configuration/columns.rb', line 17

def each
  @columns.each_with_index{|column,index|
    if column.is_a?(Lolita::Configuration::Column)
      yield column
    else
      raise "Any column must be Lolita::Configuratin::Column object instead of #{column.class}."
    end
  }
end

#generate!Object



27
28
29
30
31
32
# File 'lib/lolita/configuration/columns.rb', line 27

def generate!
  @columns.clear
  @dbi.fields.each_with_index{|field,index|
    @columns[index]=Lolita::Configuration::Column.new(field)
  }
end