Class: GroupedScope::SelfGroupping
- Inherits:
-
Object
- Object
- GroupedScope::SelfGroupping
show all
- Defined in:
- lib/grouped_scope/self_grouping.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(proxy_owner) ⇒ SelfGroupping
Returns a new instance of SelfGroupping.
15
16
17
18
|
# File 'lib/grouped_scope/self_grouping.rb', line 15
def initialize(proxy_owner)
raise NoGroupIdError.new(proxy_owner) unless proxy_owner.class.column_names.include?('group_id')
@proxy_owner = proxy_owner
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/grouped_scope/self_grouping.rb', line 94
def method_missing(method, *args)
if proxy_class.grouped_reflections[method]
if block_given?
proxy_owner.send(:"grouped_scope_#{method}", *args) { |*block_args| yield(*block_args) }
else
proxy_owner.send(:"grouped_scope_#{method}", *args)
end
elsif grouped_proxy.respond_to?(method)
if block_given?
grouped_proxy.send(method, *args) { |*block_args| yield(*block_args) }
else
grouped_proxy.send(method, *args)
end
else
super
end
end
|
Instance Attribute Details
#proxy_owner ⇒ Object
Returns the value of attribute proxy_owner.
4
5
6
|
# File 'lib/grouped_scope/self_grouping.rb', line 4
def proxy_owner
@proxy_owner
end
|
#reflection ⇒ Object
Returns the value of attribute reflection.
4
5
6
|
# File 'lib/grouped_scope/self_grouping.rb', line 4
def reflection
@reflection
end
|
Instance Method Details
#blank? ⇒ Boolean
20
21
22
|
# File 'lib/grouped_scope/self_grouping.rb', line 20
def blank?
proxy_owner.group_id.blank?
end
|
#ids ⇒ Object
28
29
30
|
# File 'lib/grouped_scope/self_grouping.rb', line 28
def ids
grouped_scoped_ids.map(&primary_key.to_sym)
end
|
#ids_sql ⇒ Object
32
33
34
|
# File 'lib/grouped_scope/self_grouping.rb', line 32
def ids_sql
Arel.sql(grouped_scoped_ids.to_sql)
end
|
#present? ⇒ Boolean
24
25
26
|
# File 'lib/grouped_scope/self_grouping.rb', line 24
def present?
!blank?
end
|
#quoted_ids ⇒ Object
36
37
38
|
# File 'lib/grouped_scope/self_grouping.rb', line 36
def quoted_ids
ids.map { |id| quote_value(id,columns_hash[primary_key]) }.join(',')
end
|
#respond_to?(method, include_private = false) ⇒ Boolean
47
48
49
|
# File 'lib/grouped_scope/self_grouping.rb', line 47
def respond_to?(method, include_private=false)
super || proxy_class.grouped_reflections[method].present? || grouped_proxy.respond_to?(method, include_private)
end
|
#with_reflection(reflection) ⇒ Object
40
41
42
43
44
45
|
# File 'lib/grouped_scope/self_grouping.rb', line 40
def with_reflection(reflection)
@reflection = reflection
yield
ensure
@reflection = nil
end
|