Module: Ice::CubeAssociation

Included in:
BaseCube
Defined in:
lib/ice/cube_association.rb

Instance Method Summary collapse

Instance Method Details

#belongs_to(*args) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/ice/cube_association.rb', line 3

def belongs_to(*args)
  args.each do |sym|
    belongs_to = %{
    def #{sym}
      @source.#{sym}.to_ice
    end
    def #{sym}_id
      @source.#{sym}_id
    end
    }
    class_eval belongs_to
  end
end

#has_many(*args) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ice/cube_association.rb', line 17

def has_many(*args)
  args.each do |sym|
    has_many = %{
    def #{sym}
      @source.#{sym}.map(&:to_ice)
    end
    def has_#{sym}
      ! @source.#{sym}.empty?
    end
    def num_#{sym}
      @source.#{sym}.count
    end
    def #{sym.to_s.singularize}_ids
       @source.#{sym.to_s.singularize}_ids
    end
    }
    class_eval has_many
  end

end