Sha256: f17057a84e0f7e3f2e43a03d46edf52af80060b9099da5fdfd1de85a6a9de411

Contents?: true

Size: 1.24 KB

Versions: 7

Compression:

Stored size: 1.24 KB

Contents

require 'active_model/naming'

module DataMapper
  module ActiveModel

    module ClassMethods

      # Returns an ActiveModel::Name object for module. It can be
      # used to retrieve all kinds of naming-related information.
      def model_name
        @_model_name ||= ::ActiveModel::Name.new(self)
      end

    end

    module InstanceMethods

      def to_model
        self
      end

      def persisted?
        saved?
      end

      def to_key
        key
      end

      def to_param
        return nil if key.nil?
        if key.length > 1
          raise "You need to implement #to_param yourself to support this key: #{self.class.key.inspect}"
        else
          self.key.first.to_s
        end
      end

      # Define the minimum requirements if the resource
      # has no concept of validation baked in, which
      # happens if dm-validations is not required.
      unless respond_to?(:validatable?)

        def valid?
          true
        end

        def errors
          obj = Object.new
          def obj.[](key)         [] end
          def obj.full_messages() [] end
          obj
        end

      end

    end

  end

  Model.append_extensions(ActiveModel::ClassMethods)
  Model.append_inclusions(ActiveModel::InstanceMethods)

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
dm-active_model-1.0.2 lib/dm-active_model.rb
dm-active_model-1.0.1 lib/dm-active_model.rb
dm-active_model-1.0.0 lib/dm-active_model.rb
dm-active_model-1.0.0.rc3 lib/dm-active_model.rb
dm-active_model-1.0.0.rc2 lib/dm-active_model.rb
dm-active_model-1.0.0.rc1 lib/dm-active_model.rb
dm-active_model-0.4.0 lib/dm-active_model.rb