Class: DeclarativeGrid::Base
- Inherits:
-
Object
- Object
- DeclarativeGrid::Base
- Defined in:
- lib/declarative_grid/base.rb
Instance Attribute Summary collapse
-
#records ⇒ Object
Attributes.
Instance Method Summary collapse
-
#initialize(records = nil) ⇒ Base
constructor
Constructor.
-
#inspect ⇒ Object
Prevent from @records dumping.
-
#renderer(name) ⇒ Object
Renderer by name.
Methods included from Model
column, columns, inherited, row
Methods included from Renderers
Constructor Details
#initialize(records = nil) ⇒ Base
Constructor
Usage 1: grid = MyGrid.new { MyRecord.all }
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/declarative_grid/base.rb', line 13 def initialize(records = nil) if block_given? STDERR.puts 'WARNING: block-style instantization is deprecated' records ||= yield end if defined? ::ActiveRecord if records.is_a?(::ActiveRecord::Relation) or (records.is_a?(Class) and records.ancestors.include?(::ActiveRecord::Base)) records = Enumerator.new records, :find_each end end if defined? ::Sequel if records.is_a?(Class) && records.ancestors.include?(::Sequel::Model) raise unless records.is_a?(Enumerable) elsif records.is_a?(::Sequel::Dataset) raise unless records.is_a?(Enumerable) end end self.records = records end |
Instance Attribute Details
#records ⇒ Object
Attributes
7 8 9 |
# File 'lib/declarative_grid/base.rb', line 7 def records @records end |
Instance Method Details
#inspect ⇒ Object
Prevent from @records dumping
44 45 46 |
# File 'lib/declarative_grid/base.rb', line 44 def inspect self.class.inspect end |
#renderer(name) ⇒ Object
Renderer by name
39 40 41 |
# File 'lib/declarative_grid/base.rb', line 39 def renderer(name) self.class.renderer_classes[name].new(self.records) end |