Class: QueryTemplate
- Inherits:
-
Object
- Object
- QueryTemplate
- Defined in:
- app/models/query_template.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#search ⇒ Object
readonly
Returns the value of attribute search.
Instance Method Summary collapse
- #auto_pin? ⇒ Boolean
-
#initialize(klass, options) ⇒ QueryTemplate
constructor
A new instance of QueryTemplate.
- #query_params ⇒ Object
- #result_set ⇒ Object
- #result_set_length ⇒ Object
- #selected_columns ⇒ Object
- #show_count? ⇒ Boolean
- #title ⇒ Object
- #to_params(options = {}) ⇒ Object
Constructor Details
#initialize(klass, options) ⇒ QueryTemplate
Returns a new instance of QueryTemplate.
4 5 6 7 8 9 10 11 12 13 14 |
# File 'app/models/query_template.rb', line 4 def initialize(klass, ) @search_class = klass @options = .dup || {} @options[:auto_count] = true if @options[:auto_count].nil? @search = klass.new(query_params: @options[:query_params], selected_columns: @options[:selected_columns], sort_columns: @options[:sort_columns].presence || [], sort_direction: @options[:sort_direction], set_limit: @options[:set_limit], pinned: @options[:pinned] || false) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
2 3 4 |
# File 'app/models/query_template.rb', line 2 def @options end |
#search ⇒ Object (readonly)
Returns the value of attribute search.
2 3 4 |
# File 'app/models/query_template.rb', line 2 def search @search end |
Instance Method Details
#auto_pin? ⇒ Boolean
29 30 31 |
# File 'app/models/query_template.rb', line 29 def auto_pin? @options[:auto_pin] end |
#query_params ⇒ Object
37 38 39 |
# File 'app/models/query_template.rb', line 37 def query_params @options[:query_params] end |
#result_set ⇒ Object
53 54 55 |
# File 'app/models/query_template.rb', line 53 def result_set @search.perform(nil, nil, nil, nil, nil, false, true) end |
#result_set_length ⇒ Object
45 46 47 48 49 50 51 |
# File 'app/models/query_template.rb', line 45 def result_set_length begin result_set.size rescue StandardError nil end || result_set.size end |
#selected_columns ⇒ Object
41 42 43 |
# File 'app/models/query_template.rb', line 41 def selected_columns @options[:selected_columns] end |
#show_count? ⇒ Boolean
33 34 35 |
# File 'app/models/query_template.rb', line 33 def show_count? @options[:auto_count] end |
#title ⇒ Object
25 26 27 |
# File 'app/models/query_template.rb', line 25 def title @options[:title] end |
#to_params(options = {}) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'app/models/query_template.rb', line 16 def to_params( = {}) hsh = { type: @search_class.name, search: @search.attributes } hsh.deep_merge() Hash[*hsh.select { |_k, v| v.present? }.flatten] # Only non nil end |