Class: GroupedScope::SelfGroupping

Inherits:
Object
  • Object
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.

Raises:



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, &block) ⇒ Object (private)



68
69
70
71
72
73
74
# File 'lib/grouped_scope/self_grouping.rb', line 68

def method_missing(method, *args, &block)
  if proxy_class.grouped_scopes[method]
    proxy_owner.send("grouped_scope_#{method}", *args, &block)
  else
    super
  end
end

Instance Attribute Details

#proxy_ownerObject (readonly)

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

Instance Method Details

#idsObject



20
21
22
# File 'lib/grouped_scope/self_grouping.rb', line 20

def ids
  @ids ||= find_selves(group_id_scope_options).map(&:id)
end

#quoted_idsObject



24
25
26
# File 'lib/grouped_scope/self_grouping.rb', line 24

def quoted_ids
  ids.map { |id| quote_value(id,columns_hash[primary_key]) }.join(',')
end

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/grouped_scope/self_grouping.rb', line 28

def respond_to?(method, include_private=false)
  super || !proxy_class.grouped_scopes[method].blank?
end