Class: Upmin::Query
- Inherits:
-
Object
- Object
- Upmin::Query
- Defined in:
- lib/upmin/query.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#search_options ⇒ Object
readonly
Returns the value of attribute search_options.
Instance Method Summary collapse
-
#initialize(klass, search_options = {}, options = {}) ⇒ Query
constructor
A new instance of Query.
- #paginated_results ⇒ Object
- #results ⇒ Object
- #upmin_results ⇒ Object
Constructor Details
#initialize(klass, search_options = {}, options = {}) ⇒ Query
Returns a new instance of Query.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/upmin/query.rb', line 11 def initialize(klass, = {}, = {}) if klass.active_record? extend Upmin::ActiveRecord::Query elsif klass.data_mapper? extend Upmin::DataMapper::Query else raise ArgumentError.new(klass) end @klass = klass @search_options = @page = [:page] @per_page = [:per_page] end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
4 5 6 |
# File 'lib/upmin/query.rb', line 4 def klass @klass end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
6 7 8 |
# File 'lib/upmin/query.rb', line 6 def page @page end |
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page.
7 8 9 |
# File 'lib/upmin/query.rb', line 7 def per_page @per_page end |
#search_options ⇒ Object (readonly)
Returns the value of attribute search_options.
5 6 7 |
# File 'lib/upmin/query.rb', line 5 def @search_options end |
Instance Method Details
#paginated_results ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/upmin/query.rb', line 30 def paginated_results return @paginated_results if defined?(@paginated_results) if page && per_page pr = Upmin::Paginator.paginate(results, page, per_page) else pr = Upmin::Paginator.paginate(results) end @paginated_results = pr return @paginated_results end |
#results ⇒ Object
26 27 28 |
# File 'lib/upmin/query.rb', line 26 def results raise NotImplementedError end |
#upmin_results ⇒ Object
41 42 43 44 45 |
# File 'lib/upmin/query.rb', line 41 def upmin_results return @upmin_results if defined?(@upmin_results) @upmin_results = paginated_results.map{ |r| r.upmin_model } return @upmin_results end |