Sha256: 73bd28fda1c1a9086f798d867b35d22eeba520853908e07ca3bb2f45fa0cfcaa

Contents?: true

Size: 1010 Bytes

Versions: 63

Compression:

Stored size: 1010 Bytes

Contents

# encoding: UTF-8
module MongoMapper
  module Plugins
    module Rails
      def self.configure(model)
        model.extend ActiveModel::Naming if defined?(ActiveModel)
      end

      module InstanceMethods
        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_typecast(name)
          read_key_before_typecast(name)
        end

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

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

        def has_many(*args)
          many(*args)
        end

        def column_names
          keys.keys
        end

        def human_name
          self.name.demodulize.titleize
        end
      end
    end
  end
end

Version data entries

63 entries across 63 versions & 9 rubygems

Version Path
mongo_mapper-0.8.0 lib/mongo_mapper/plugins/rails.rb
pwnash-mongo_mapper-0.7.6 lib/mongo_mapper/plugins/rails.rb
mongo_mapper_ign-0.7.6 lib/mongo_mapper/plugins/rails.rb