Class: RDBr::Web::ColumnPreferences
- Inherits:
-
Object
- Object
- RDBr::Web::ColumnPreferences
- Defined in:
- lib/rdbr/web/column_preferences.rb
Constant Summary collapse
- TRAILING_COLUMNS =
%w[created_at updated_at discarded_at].freeze
Instance Attribute Summary collapse
-
#cookie_name ⇒ Object
readonly
Returns the value of attribute cookie_name.
-
#storage_key ⇒ Object
readonly
Returns the value of attribute storage_key.
Instance Method Summary collapse
-
#initialize(database:, namespace:, relation:, fixed_columns:, value: nil) ⇒ ColumnPreferences
constructor
A new instance of ColumnPreferences.
- #ordered_columns ⇒ Object
- #visible_columns ⇒ Object
Constructor Details
#initialize(database:, namespace:, relation:, fixed_columns:, value: nil) ⇒ ColumnPreferences
Returns a new instance of ColumnPreferences.
10 11 12 13 14 15 16 |
# File 'lib/rdbr/web/column_preferences.rb', line 10 def initialize(database:, namespace:, relation:, fixed_columns:, value: nil) identity = [ database.adapter, database.name, namespace.name, relation.name ].join('/') @columns = relation.columns.reject{|column| fixed_columns.include?(column.name) } @preference = parse(value) @cookie_name = "rdbr_columns_#{Digest::SHA256.hexdigest(identity).slice(0, 16)}" @storage_key = "rdbr.columns.#{identity}" end |
Instance Attribute Details
#cookie_name ⇒ Object (readonly)
Returns the value of attribute cookie_name.
8 9 10 |
# File 'lib/rdbr/web/column_preferences.rb', line 8 def @cookie_name end |
#storage_key ⇒ Object (readonly)
Returns the value of attribute storage_key.
8 9 10 |
# File 'lib/rdbr/web/column_preferences.rb', line 8 def storage_key @storage_key end |
Instance Method Details
#ordered_columns ⇒ Object
18 19 20 21 |
# File 'lib/rdbr/web/column_preferences.rb', line 18 def ordered_columns preferred_names.filter_map{|name| columns_by_name[name] } + default_columns.reject{|column| preferred_names.include?(column.name) } end |
#visible_columns ⇒ Object
23 24 25 26 |
# File 'lib/rdbr/web/column_preferences.rb', line 23 def visible_columns visible = ordered_columns.reject{|column| hidden_names.include?(column.name) } visible.empty? ? ordered_columns.first(1) : visible end |