Class: Charty::TableAdapters::ActiveRecordAdapter
- Inherits:
-
Object
- Object
- Charty::TableAdapters::ActiveRecordAdapter
- Includes:
- Enumerable
- Defined in:
- lib/charty/table_adapters/active_record_adapter.rb
Instance Attribute Summary collapse
-
#column_names ⇒ Object
readonly
Returns the value of attribute column_names.
Class Method Summary collapse
Instance Method Summary collapse
- #[](row, column) ⇒ Object
-
#initialize(data) ⇒ ActiveRecordAdapter
constructor
A new instance of ActiveRecordAdapter.
Constructor Details
#initialize(data) ⇒ ActiveRecordAdapter
Returns a new instance of ActiveRecordAdapter.
12 13 14 15 16 |
# File 'lib/charty/table_adapters/active_record_adapter.rb', line 12 def initialize(data) @data = check_type(ActiveRecord::Relation, data, :data) @column_names = @data.column_names.freeze @columns = nil end |
Instance Attribute Details
#column_names ⇒ Object (readonly)
Returns the value of attribute column_names.
18 19 20 |
# File 'lib/charty/table_adapters/active_record_adapter.rb', line 18 def column_names @column_names end |
Class Method Details
.supported?(data) ⇒ Boolean
8 9 10 |
# File 'lib/charty/table_adapters/active_record_adapter.rb', line 8 def self.supported?(data) defined?(ActiveRecord::Relation) && data.is_a?(ActiveRecord::Relation) end |
Instance Method Details
#[](row, column) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/charty/table_adapters/active_record_adapter.rb', line 20 def [](row, column) fetch_records unless @columns if row @columns[resolve_column_index(column)][row] else @columns[resolve_column_index(column)] end end |