Class: Spider::Model::Request
- Defined in:
- lib/spiderfw/model/request.rb
Overview
The request object specifies which data is to be loaded for a model. It is similar in purpose to the SELECT … part of an SQL query.
Instance Attribute Summary collapse
-
#expandable ⇒ bool
If true, the request will be expanded with lazy groups on load.
-
#polymorphs ⇒ bool
readonly
Find also the given subclasses of the queried model.
-
#total_rows ⇒ bool
If true, the total number of rows returned by the query is requested.
Class Method Summary collapse
-
.strict(val = nil, params = {}) ⇒ Request
Initializes a Request that should not be expanded by the Mapper.
Instance Method Summary collapse
-
#expandable? ⇒ bool
True if the Request can be expanded by the mapper (using lazy groups).
-
#initialize(val = nil, params = {}) ⇒ Request
constructor
A new instance of Request.
-
#only_polymorphs ⇒ self
Requests that only the subclasses requested with #with_polymorphs are returned, not the mapper’s base class.
-
#only_polymorphs? ⇒ bool
True if only polymorphs should be returned.
-
#polymorphs? ⇒ bool
True if there are requested polymorphs.
- #request(element) ⇒ void
-
#with_polymorphs(type, request) ⇒ Object
Requests that the mapper looks for subclasses of the given type, loading additional subclass specific elements specified in the request.
-
#with_superclass ⇒ self
Requests that the mapper retrieves also objects belonging to the model’s superclass.
-
#with_superclass? ⇒ bool
True if the superclass was requested with #with_superclass.
Methods inherited from ModelHash
#[], #[]=, #get_deep_obj, #modelhash_orig_set
Constructor Details
#initialize(val = nil, params = {}) ⇒ Request
Returns a new instance of Request.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/spiderfw/model/request.rb', line 19 def initialize(val=nil, params={}) if (val.is_a?(Array)) super() val.each{ |v| request(v) } else super(val) end @total_rows = params[:total_rows] @polymorphs = {} @expandable = true end |
Instance Attribute Details
#expandable ⇒ bool
Returns if true, the request will be expanded with lazy groups on load.
14 15 16 |
# File 'lib/spiderfw/model/request.rb', line 14 def @expandable end |
#polymorphs ⇒ bool (readonly)
Returns find also the given subclasses of the queried model.
12 13 14 |
# File 'lib/spiderfw/model/request.rb', line 12 def polymorphs @polymorphs end |
#total_rows ⇒ bool
Returns if true, the total number of rows returned by the query is requested.
10 11 12 |
# File 'lib/spiderfw/model/request.rb', line 10 def total_rows @total_rows end |
Class Method Details
.strict(val = nil, params = {}) ⇒ Request
Initializes a Request that should not be expanded by the Mapper
35 36 37 38 39 |
# File 'lib/spiderfw/model/request.rb', line 35 def self.strict(val=nil, params={}) r = self.new(val, params) r. = false r end |
Instance Method Details
#expandable? ⇒ bool
Returns true if the Request can be expanded by the mapper (using lazy groups).
95 96 97 |
# File 'lib/spiderfw/model/request.rb', line 95 def @expandable end |
#only_polymorphs ⇒ self
Requests that only the subclasses requested with #with_polymorphs are returned, not the mapper’s base class
71 72 73 74 |
# File 'lib/spiderfw/model/request.rb', line 71 def only_polymorphs @only_polymorphs = true return self end |
#only_polymorphs? ⇒ bool
Returns True if only polymorphs should be returned.
77 78 79 |
# File 'lib/spiderfw/model/request.rb', line 77 def only_polymorphs? @only_polymorphs end |
#polymorphs? ⇒ bool
Returns True if there are requested polymorphs.
64 65 66 |
# File 'lib/spiderfw/model/request.rb', line 64 def polymorphs? @polymorphs.empty? ? false : true end |
#request(element) ⇒ void
This method returns an undefined value.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/spiderfw/model/request.rb', line 43 def request(element) # :nodoc: if element.is_a?(Element) self[element.name.to_s] = true elsif element.is_a?(String) element.split(',').each do |el| self[el.strip] = true end else self[element] = true end end |
#with_polymorphs(type, request) ⇒ Object
Requests that the mapper looks for subclasses of the given type, loading additional subclass specific elements specified in the request
59 60 61 |
# File 'lib/spiderfw/model/request.rb', line 59 def with_polymorphs(type, request) @polymorphs[type] = request end |
#with_superclass ⇒ self
Requests that the mapper retrieves also objects belonging to the model’s superclass
83 84 85 86 |
# File 'lib/spiderfw/model/request.rb', line 83 def with_superclass @with_superclass = true return self end |
#with_superclass? ⇒ bool
Returns true if the superclass was requested with #with_superclass.
89 90 91 |
# File 'lib/spiderfw/model/request.rb', line 89 def with_superclass? @with_superclass end |