Class: TableCloth::Base
- Inherits:
-
Object
- Object
- TableCloth::Base
- Defined in:
- lib/table_cloth/base.rb
Constant Summary collapse
- NoPresenterError =
Class.new(Exception)
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#view ⇒ Object
readonly
Returns the value of attribute view.
Class Method Summary collapse
- .add_column(options) ⇒ Object
- .column(*args, &block) ⇒ Object
- .columns ⇒ Object
- .config ⇒ Object
- .presenter(klass = nil) ⇒ Object
Instance Method Summary collapse
- #config ⇒ Object
-
#initialize(collection, view) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(collection, view) ⇒ Base
Returns a new instance of Base.
7 8 9 10 |
# File 'lib/table_cloth/base.rb', line 7 def initialize(collection, view) @collection = collection @view = view end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
5 6 7 |
# File 'lib/table_cloth/base.rb', line 5 def collection @collection end |
#view ⇒ Object (readonly)
Returns the value of attribute view.
5 6 7 |
# File 'lib/table_cloth/base.rb', line 5 def view @view end |
Class Method Details
.add_column(options) ⇒ Object
48 49 50 51 |
# File 'lib/table_cloth/base.rb', line 48 def add_column() @columns ||= {} @columns[[:name]] = end |
.column(*args, &block) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/table_cloth/base.rb', line 28 def column(*args, &block) = args. || {} [:proc] = block if block_given? column_class = .delete(:using) || Column args.each do |name| add_column(class: column_class, options: , name: name) end end |
.columns ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/table_cloth/base.rb', line 39 def columns @columns ||= {} if superclass.respond_to? :columns @columns = superclass.columns.merge(@columns) end @columns end |
.config ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/table_cloth/base.rb', line 53 def config @config ||= if superclass.respond_to?(:config) superclass.config.dup else Configuration.new end end |
.presenter(klass = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/table_cloth/base.rb', line 17 def presenter(klass=nil) return @presenter = klass if klass return @presenter if @presenter if superclass.respond_to?(:presenter) superclass.presenter else raise NoPresenterError, "No Presenter" end end |
Instance Method Details
#config ⇒ Object
12 13 14 |
# File 'lib/table_cloth/base.rb', line 12 def config self.class.config end |