Class: Spider::Model::Request

Inherits:
ModelHash show all
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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ModelHash

#[], #[]=, #get_deep_obj, #modelhash_orig_set

Constructor Details

#initialize(val = nil, params = {}) ⇒ 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

#expandablebool



14
15
16
# File 'lib/spiderfw/model/request.rb', line 14

def expandable
  @expandable
end

#polymorphsbool (readonly)



12
13
14
# File 'lib/spiderfw/model/request.rb', line 12

def polymorphs
  @polymorphs
end

#total_rowsbool



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.expandable = false
    r
end

Instance Method Details

#expandable?bool



95
96
97
# File 'lib/spiderfw/model/request.rb', line 95

def expandable?
    @expandable
end

#only_polymorphsself

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



77
78
79
# File 'lib/spiderfw/model/request.rb', line 77

def only_polymorphs?
    @only_polymorphs
end

#polymorphs?bool



64
65
66
# File 'lib/spiderfw/model/request.rb', line 64

def polymorphs?
    @polymorphs.empty? ? false : true
end

#request(element) ⇒ void



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_superclassself

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



89
90
91
# File 'lib/spiderfw/model/request.rb', line 89

def with_superclass?
    @with_superclass
end