Class: ActiveAny::Relation
- Inherits:
-
Object
- Object
- ActiveAny::Relation
show all
- Includes:
- FinderMethods, QueryMethods, Enumerable
- Defined in:
- lib/active_any/relation.rb,
lib/active_any/relation/merger.rb,
lib/active_any/relation/order_clause.rb,
lib/active_any/relation/where_clause.rb,
lib/active_any/relation/query_methods.rb,
lib/active_any/relation/finder_methods.rb
Defined Under Namespace
Modules: FinderMethods, QueryMethods
Classes: HashMerger, ImmutableRelation, Merger, OrderClause, WhereClause
Constant Summary
collapse
- MULTI_VALUE_METHODS =
i[group includes join].freeze
- SINGLE_VALUE_METHODS =
i[limit].freeze
- CLAUSE_METHODS =
i[where order].freeze
- VALUE_METHODS =
(MULTI_VALUE_METHODS + SINGLE_VALUE_METHODS + CLAUSE_METHODS).freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#get_value, #group, #group!, #includes, #includes!, #limit, #limit!, #order, #order!, #reverse_order, #reverse_order!, #set_value, #take, #values, #where, #where!
#find_by, #first, #last
Constructor Details
#initialize(klass) ⇒ Relation
Returns a new instance of Relation.
25
26
27
28
29
30
|
# File 'lib/active_any/relation.rb', line 25
def initialize(klass)
@klass = klass
@records = []
@loaded = false
@values = {}
end
|
Instance Attribute Details
Returns the value of attribute klass.
11
12
13
|
# File 'lib/active_any/relation.rb', line 11
def klass
@klass
end
|
Returns the value of attribute loaded.
11
12
13
|
# File 'lib/active_any/relation.rb', line 11
def loaded
@loaded
end
|
Class Method Details
.create(klass, *args) ⇒ Object
21
22
23
|
# File 'lib/active_any/relation.rb', line 21
def self.create(klass, *args)
new(klass, *args)
end
|
Instance Method Details
#eager_loading? ⇒ Boolean
84
85
86
|
# File 'lib/active_any/relation.rb', line 84
def eager_loading?
false
end
|
#initialize_copy ⇒ Object
63
64
65
66
67
|
# File 'lib/active_any/relation.rb', line 63
def initialize_copy(*)
@values = @values.dup
reset
super
end
|
79
80
81
82
|
# File 'lib/active_any/relation.rb', line 79
def load
exec_query unless loaded
self
end
|
#loaded? ⇒ Boolean
75
76
77
|
# File 'lib/active_any/relation.rb', line 75
def loaded?
@loaded
end
|
#merge(other) ⇒ Object
36
37
38
39
40
41
42
43
44
|
# File 'lib/active_any/relation.rb', line 36
def merge(other)
if other.is_a?(Array)
records & other
elsif other
spawn.merge!(other)
else
raise ArgumentError, "invalid argument: #{other.inspect}."
end
end
|
#merge!(other) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/active_any/relation.rb', line 46
def merge!(other)
if other.is_a?(Hash)
Relation::HashMerger.new(self, other).merge
elsif other.is_a?(Relation)
Relation::Merger.new(self, other).merge
elsif other.respond_to?(:to_proc)
instance_exec(&other)
else
raise ArgumentError, "#{other.inspect} is not an ActiveAny::Relation"
end
end
|
58
59
60
61
|
# File 'lib/active_any/relation.rb', line 58
def records
load
@records
end
|
69
70
71
72
73
|
# File 'lib/active_any/relation.rb', line 69
def reset
@loaded = nil
@records = [].freeze
self
end
|
32
33
34
|
# File 'lib/active_any/relation.rb', line 32
def to_a
records.dup
end
|