Class: AWS::Record::Scope
- Inherits:
-
Object
- Object
- AWS::Record::Scope
show all
- Includes:
- Enumerable
- Defined in:
- lib/aws/record/scope.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(base_class, options = {}) ⇒ Scope
Returns a new instance of Scope.
22
23
24
25
|
# File 'lib/aws/record/scope.rb', line 22
def initialize base_class, options = {}
@base_class = base_class
@options = options
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(scope_name, *args) ⇒ Object
105
106
107
108
|
# File 'lib/aws/record/scope.rb', line 105
def method_missing scope_name, *args
_merge_scope(base_class.send(scope_name, *args))
end
|
Instance Attribute Details
#base_class ⇒ Object
Returns the value of attribute base_class.
20
21
22
|
# File 'lib/aws/record/scope.rb', line 20
def base_class
@base_class
end
|
Instance Method Details
#count(options = {}) ⇒ Object
Also known as:
size
45
46
47
48
49
50
51
52
|
# File 'lib/aws/record/scope.rb', line 45
def count(options = {})
if scope = _handle_options(options) and
scope != self
scope.count
else
_item_collection.count
end
end
|
#each(&block) ⇒ Object
70
71
72
73
74
75
76
|
# File 'lib/aws/record/scope.rb', line 70
def each &block
if block_given?
_each_object(&block)
else
Enumerator.new(self, :"_each_object")
end
end
|
#find(id_or_mode, options = {}) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/aws/record/scope.rb', line 27
def find id_or_mode, options = {}
scope = _handle_options(options)
case
when id_or_mode == :all then scope
when id_or_mode == :first then scope.limit(1).first
when scope.send(:_empty?) then base_class[id_or_mode]
else
object = scope.where('itemName() = ?', id_or_mode).limit(1).first
if object.nil?
raise RecordNotFound, "no data found for id: #{id_or_mode}"
end
object
end
end
|
#limit(limit) ⇒ Object
66
67
68
|
# File 'lib/aws/record/scope.rb', line 66
def limit limit
_with(:limit => limit)
end
|
#order(attribute, order = :asc) ⇒ Object
62
63
64
|
# File 'lib/aws/record/scope.rb', line 62
def order attribute, order = :asc
_with(:order => [attribute, order])
end
|
#where(*conditions) ⇒ Object
55
56
57
58
59
60
|
# File 'lib/aws/record/scope.rb', line 55
def where *conditions
if conditions.empty?
raise ArgumentError, 'missing required condition'
end
_with(:where => Record.as_array(@options[:where]) + [conditions])
end
|