Module: EasyUnionSet::GroupMethods

Defined in:
lib/easy_union_set.rb

Instance Method Summary collapse

Instance Method Details

#&(ar_rel) ⇒ Object



6
7
8
9
10
11
# File 'lib/easy_union_set.rb', line 6

def & ar_rel
  set = self.intersect(ar_rel)
  table_alias = arel_table.create_table_alias(set, table_name)

  ancestors.first.from(table_alias)
end

#|(ar_rel) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/easy_union_set.rb', line 13

def | ar_rel
  union = case ar_rel
          when ActiveRecord::Relation
            self.union(ar_rel)
          when Hash
            ar_rel.assert_valid_keys(:all)
            self.union(:all, ar_rel[:all])          
          end
  
  table_alias = arel_table.create_table_alias(union, table_name)

  ancestors.first.from(table_alias)
end