Sha256: ea905afd9e568fe35d6cc2af8fcd79237a1ab42a1eeaedae2524aed22ea22c5c

Contents?: true

Size: 736 Bytes

Versions: 17

Compression:

Stored size: 736 Bytes

Contents

module Ice
  module CubeAssociation
    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

    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
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
ice-0.5.1 lib/ice/cube_association.rb
ice-0.5.0 lib/ice/cube_association.rb
ice-0.4.4 lib/ice/cube_association.rb
ice-0.4.3 lib/ice/cube_association.rb
ice-0.4.2 lib/ice/cube_association.rb
ice-0.4.1 lib/ice/cube_association.rb
ice-0.4.0 lib/ice/cube_association.rb
ice-0.3.0 lib/ice/cube_association.rb
ice-0.2.4 lib/ice/cube_association.rb
ice-0.2.3 lib/ice/cube_association.rb
ice-0.2.2 lib/ice/cube_association.rb
ice-0.2.1 lib/ice/cube_association.rb
ice-0.2.0 lib/ice/cube_association.rb
ice-0.1.3 lib/ice/cube_association.rb
ice-0.1.2 lib/ice/cube_association.rb
ice-0.1.1 lib/ice/cube_association.rb
ice-0.1.0 lib/ice/cube_association.rb