Class: Lolita::Configuration::Columns
- Includes:
- Enumerable, Builder, ObservedArray
- Defined in:
- lib/lolita/configuration/columns.rb
Instance Attribute Summary collapse
-
#dbi ⇒ Object
readonly
Returns the value of attribute dbi.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
-
#by_name(name) ⇒ Object
Find first column by name.
-
#column(*args, &block) ⇒ Object
Add column to columns Array.
- #each ⇒ Object
- #generate! ⇒ Object
-
#initialize(dbi, *args, &block) ⇒ Columns
constructor
A new instance of Columns.
- #populate ⇒ Object
Methods included from Builder
#build, #builder, #builder=, #builder_default_name, #builder_default_options, #builder_default_state
Methods included from ObservedArray
#<<, #[]=, #insert, #method_missing, #push
Constructor Details
#initialize(dbi, *args, &block) ⇒ Columns
Returns a new instance of Columns.
12 13 14 15 16 17 18 |
# File 'lib/lolita/configuration/columns.rb', line 12 def initialize(dbi, *args, &block) @dbi=dbi @columns=[] @generated_yet = (block_given? || (args && args.any?)) set_attributes(*args) self.instance_eval(&block) if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Lolita::ObservedArray
Instance Attribute Details
#dbi ⇒ Object (readonly)
Returns the value of attribute dbi.
9 10 11 |
# File 'lib/lolita/configuration/columns.rb', line 9 def dbi @dbi end |
#parent ⇒ Object
Returns the value of attribute parent.
10 11 12 |
# File 'lib/lolita/configuration/columns.rb', line 10 def parent @parent end |
Instance Method Details
#by_name(name) ⇒ Object
Find first column by name
27 28 29 30 31 32 |
# File 'lib/lolita/configuration/columns.rb', line 27 def by_name(name) name = name.to_sym self.detect do |column| column.name == name end end |
#column(*args, &block) ⇒ Object
Add column to columns Array. Receive attributes for column as Hash and/or block.
21 22 23 24 |
# File 'lib/lolita/configuration/columns.rb', line 21 def column *args, &block @columns << build_element(*args,&block) @columns.last end |
#each ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/lolita/configuration/columns.rb', line 34 def each self.populate @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
46 47 48 49 50 51 52 53 54 |
# File 'lib/lolita/configuration/columns.rb', line 46 def generate! @generated_yet = true @columns.clear @dbi.fields.each_with_index{|field,index| unless field.technical? column(field) end } end |
#populate ⇒ Object
56 57 58 |
# File 'lib/lolita/configuration/columns.rb', line 56 def populate self.generate! if @columns.empty? && !@generated_yet end |