Class: Ryext::Query
Constant Summary collapse
- PARAM_KEYS =
[ :start, :limit ]
Instance Attribute Summary collapse
-
#account ⇒ Object
Returns the value of attribute account.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#parent_klass ⇒ Object
readonly
Returns the value of attribute parent_klass.
Instance Method Summary collapse
- #base_url ⇒ Object
- #collection ⇒ Object
- #each(&block) ⇒ Object
- #extract_from_params ⇒ Object
-
#initialize(klass, params = {}) ⇒ Query
constructor
A new instance of Query.
- #instance_klass ⇒ Object
- #load ⇒ Object
- #loaded? ⇒ Boolean
- #request_for_query ⇒ Object
- #to_params ⇒ Object
Constructor Details
#initialize(klass, params = {}) ⇒ Query
Returns a new instance of Query.
11 12 13 14 15 16 |
# File 'lib/ryext/query.rb', line 11 def initialize(klass, params = {}) @parent_klass = klass @params = params extract_from_params end |
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account.
5 6 7 |
# File 'lib/ryext/query.rb', line 5 def account @account end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
4 5 6 |
# File 'lib/ryext/query.rb', line 4 def params @params end |
#parent_klass ⇒ Object (readonly)
Returns the value of attribute parent_klass.
4 5 6 |
# File 'lib/ryext/query.rb', line 4 def parent_klass @parent_klass end |
Instance Method Details
#base_url ⇒ Object
26 27 28 |
# File 'lib/ryext/query.rb', line 26 def base_url @parent_klass.base_url(@params) end |
#collection ⇒ Object
52 53 54 55 |
# File 'lib/ryext/query.rb', line 52 def collection load unless loaded? @collection end |
#each(&block) ⇒ Object
38 39 40 |
# File 'lib/ryext/query.rb', line 38 def each(&block) collection.each(&block) end |
#extract_from_params ⇒ Object
18 19 20 |
# File 'lib/ryext/query.rb', line 18 def extract_from_params @account = @params.delete(:account) end |
#instance_klass ⇒ Object
22 23 24 |
# File 'lib/ryext/query.rb', line 22 def instance_klass @parent_klass.instance_klass end |
#load ⇒ Object
46 47 48 49 50 |
# File 'lib/ryext/query.rb', line 46 def load response = request_for_query @collection = response.collection.map { |x| @parent_klass.new(x, @account) } @loaded = true end |
#loaded? ⇒ Boolean
42 43 44 |
# File 'lib/ryext/query.rb', line 42 def loaded? @loaded end |
#request_for_query ⇒ Object
57 58 59 |
# File 'lib/ryext/query.rb', line 57 def request_for_query account && account.request(self) end |
#to_params ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/ryext/query.rb', line 30 def to_params if @parent_klass.respond_to?(:clean_params) @parent_klass.clean_params(@params) else @params end end |