Class: ModelExplorer::Select
- Inherits:
-
Object
- Object
- ModelExplorer::Select
- Defined in:
- lib/model_explorer/select.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#selects ⇒ Object
readonly
Returns the value of attribute selects.
Instance Method Summary collapse
- #columns ⇒ Object
-
#initialize(model, selects) ⇒ Select
constructor
A new instance of Select.
- #to_a ⇒ Object
Constructor Details
#initialize(model, selects) ⇒ Select
Returns a new instance of Select.
5 6 7 8 |
# File 'lib/model_explorer/select.rb', line 5 def initialize(model, selects) @model = model @selects = selects end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
3 4 5 |
# File 'lib/model_explorer/select.rb', line 3 def model @model end |
#selects ⇒ Object (readonly)
Returns the value of attribute selects.
3 4 5 |
# File 'lib/model_explorer/select.rb', line 3 def selects @selects end |
Instance Method Details
#columns ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/model_explorer/select.rb', line 10 def columns column_names = model.column_names return column_names if selects.blank? selected_columns = column_names & selects if selected_columns.empty? ["#{model.table_name}.*"] else ([model.primary_key] + selected_columns).uniq end end |
#to_a ⇒ Object
24 25 26 |
# File 'lib/model_explorer/select.rb', line 24 def to_a columns.map { |column| "#{model.table_name}.#{column}" } end |