Class: DeclarativeGrid::Model::Row
- Inherits:
-
Object
- Object
- DeclarativeGrid::Model::Row
- Defined in:
- lib/declarative_grid/model/row.rb
Instance Attribute Summary collapse
-
#columns_hash ⇒ Object
readonly
Attributes.
Instance Method Summary collapse
-
#columns(*names) ⇒ Object
Return a list of the columns.
-
#define_column(name, options = {}, &block) ⇒ Object
Define a column.
-
#initialize ⇒ Row
constructor
Constructor.
-
#initialize_copy(other) ⇒ Object
Copy Constructor.
Constructor Details
#initialize ⇒ Row
Constructor
9 10 11 |
# File 'lib/declarative_grid/model/row.rb', line 9 def initialize @columns_hash = {} end |
Instance Attribute Details
#columns_hash ⇒ Object (readonly)
Attributes
6 7 8 |
# File 'lib/declarative_grid/model/row.rb', line 6 def columns_hash @columns_hash end |
Instance Method Details
#columns(*names) ⇒ Object
Return a list of the columns
PARAM: names can be:
1) a list of Symbols : returns selected columns according to names
2) an empty list : returns all the columns
NOTE: the returned columns is ordered by the given names
34 35 36 37 38 39 40 41 |
# File 'lib/declarative_grid/model/row.rb', line 34 def columns(*names) names = names.flatten if names.empty? @columns_hash.values else @columns_hash.values_at *(names.map(&:to_sym)) end end |
#define_column(name, options = {}, &block) ⇒ Object
Define a column
20 21 22 23 24 |
# File 'lib/declarative_grid/model/row.rb', line 20 def define_column(name, = {}, &block) name = name.to_sym check_column_name_collision! name @columns_hash[name] = Column.new name, , &block end |
#initialize_copy(other) ⇒ Object
Copy Constructor
14 15 16 17 |
# File 'lib/declarative_grid/model/row.rb', line 14 def initialize_copy(other) super(other) @columns_hash = other.columns_hash.dup end |