Sha256: 7410a4bb73ab505c24e79b4377c4987f1674f3625d996538f7ce240ba331a38d

Contents?: true

Size: 1.1 KB

Versions: 6

Compression:

Stored size: 1.1 KB

Contents

module MongoMapper
  module Associations
    class Base
      attr_reader :type, :name, :options

      def initialize(type, name, options = {})
        @options = options
        @type = type
        @name = name
      end

      def klass
        class_name.constantize
      end

      def class_name
        @class_name ||= begin
          if cn = options[:class_name]
            cn
          elsif @type == :many
            name.to_s.singularize.camelize
          else
            name.to_s.camelize
          end
        end
      end

      def ivar
        @ivar ||= "@_#{name}"
      end

      def proxy_class
        case @type
          when :belongs_to
            if @options[:polymorphic]
              PolymorphicBelongsToProxy
            else
              BelongsToProxy
            end
          when :many
            if self.klass.embeddable?
              if @options[:polymorphic]
                PolymorphicHasManyEmbeddedProxy
              else
                HasManyEmbeddedProxy
              end
            else
              HasManyProxy
            end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fcoury-mongomapper-0.2.0 lib/mongomapper/associations/base.rb
fcoury-mongomapper-0.3.0 lib/mongomapper/associations/base.rb
fcoury-mongomapper-0.3.1 lib/mongomapper/associations/base.rb
fcoury-mongomapper-0.3.3 lib/mongomapper/associations/base.rb
fcoury-mongomapper-0.3.4 lib/mongomapper/associations/base.rb
fcoury-mongomapper-0.3.5 lib/mongomapper/associations/base.rb