Class: Charty::TableAdapters::ActiveRecordAdapter
- Inherits:
-
BaseAdapter
- Object
- BaseAdapter
- Charty::TableAdapters::ActiveRecordAdapter
- 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.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Attributes inherited from BaseAdapter
Class Method Summary collapse
Instance Method Summary collapse
- #[](row, column) ⇒ Object
- #column_length ⇒ Object
-
#initialize(data) ⇒ ActiveRecordAdapter
constructor
A new instance of ActiveRecordAdapter.
Methods inherited from BaseAdapter
#==, #column?, #compare_data_equality, #drop_na, #group_by, #melt, #sort_values
Constructor Details
#initialize(data) ⇒ ActiveRecordAdapter
Returns a new instance of ActiveRecordAdapter.
10 11 12 13 14 15 |
# File 'lib/charty/table_adapters/active_record_adapter.rb', line 10 def initialize(data) @data = check_type(ActiveRecord::Relation, data, :data) @column_names = @data.column_names.freeze self.columns = Index.new(@column_names) self.index = RangeIndex.new(0 ... length) end |
Instance Attribute Details
#column_names ⇒ Object (readonly)
Returns the value of attribute column_names.
17 18 19 |
# File 'lib/charty/table_adapters/active_record_adapter.rb', line 17 def column_names @column_names end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
17 18 19 |
# File 'lib/charty/table_adapters/active_record_adapter.rb', line 17 def data @data end |
Class Method Details
.supported?(data) ⇒ Boolean
6 7 8 |
# File 'lib/charty/table_adapters/active_record_adapter.rb', line 6 def self.supported?(data) defined?(ActiveRecord::Relation) && data.is_a?(ActiveRecord::Relation) end |
Instance Method Details
#[](row, column) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/charty/table_adapters/active_record_adapter.rb', line 27 def [](row, column) fetch_records unless @columns_cache if row @columns_cache[resolve_column_index(column)][row] else column_data = @columns_cache[resolve_column_index(column)] Vector.new(column_data, index: index, name: column) end end |
#column_length ⇒ Object
23 24 25 |
# File 'lib/charty/table_adapters/active_record_adapter.rb', line 23 def column_length column_names.length end |