Sha256: 1c183d2de3687e8be56bcedbcad2fe880e45c0a0f2306a66b660d21bb2d4e274

Contents?: true

Size: 1.34 KB

Versions: 6

Compression:

Stored size: 1.34 KB

Contents

# encoding: UTF-8
module MongoMapper
  module Plugins
    module Rails
      autoload :ActiveRecordAssociationAdapter, "mongo_mapper/plugins/rails/active_record_association_adapter"
      extend ActiveSupport::Concern

      def to_param
        id.to_s if persisted?
      end

      def to_model
        self
      end

      def to_key
        [id] if persisted?
      end

      def new_record?
        new?
      end

      def read_attribute(name)
        self[name]
      end

      def read_attribute_before_type_cast(name)
        read_key_before_type_cast(name)
      end

      def write_attribute(name, value)
        self[name] = value
      end

      module ClassMethods
        def has_one(*args)
          one(*args)
        end

        def has_many(*args, &extension)
          many(*args, &extension)
        end

        def column_names
          keys.keys
        end

        # Returns returns an ActiveRecordAssociationAdapter for an association. This adapter has an API that is a
        # subset of ActiveRecord::Reflection::AssociationReflection. This allows MongoMapper to be used with the
        # association helpers in gems like simple_form and formtastic.
        def reflect_on_association(name)
          ActiveRecordAssociationAdapter.for_association(associations[name]) if associations[name]
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
mongo_mapper-0.12.0 lib/mongo_mapper/plugins/rails.rb
lookout-mongo_mapper-0.11.3 lib/mongo_mapper/plugins/rails.rb
mongo_mapper-0.11.2 lib/mongo_mapper/plugins/rails.rb
jamieorc-mongo_mapper-0.11.1.1 lib/mongo_mapper/plugins/rails.rb
mongo_mapper-0.11.1 lib/mongo_mapper/plugins/rails.rb
mongo_mapper-0.11.0 lib/mongo_mapper/plugins/rails.rb