Sha256: f566a5528bdfd9bbb37698c8892fbb671ba8538f1d1861715f2f120430784926

Contents?: true

Size: 884 Bytes

Versions: 29

Compression:

Stored size: 884 Bytes

Contents

module CouchPotato
  module Persistence
    module ActiveModelCompliance
      begin
        require 'active_model'

        def self.included(base)
          base.extend ClassMethods
        end

        def to_model
          self
        end

        def to_partial_path
          "#{self.class.name.underscore.pluralize}/#{self.class.name.underscore}"
        end

        def errors
          super || {}
        end

        def persisted?
          !self.new?
        end

        def to_key
          persisted? ? [to_param] : nil
        end

        def destroyed?
          !!_deleted
        end

        module ClassMethods
          def model_name
            @model_name ||= ::ActiveModel::Name.new(self)
          end
        end

      rescue LoadError, NameError
        # if it's not installed you probably don't want to use it anyway
      end
    end
  end
end


Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
couch_potato-1.18.0 lib/couch_potato/persistence/active_model_compliance.rb
couch_potato-1.17.0 lib/couch_potato/persistence/active_model_compliance.rb
couch_potato-1.16.0 lib/couch_potato/persistence/active_model_compliance.rb
couch_potato-1.15.0 lib/couch_potato/persistence/active_model_compliance.rb
couch_potato-1.14.0 lib/couch_potato/persistence/active_model_compliance.rb
couch_potato-1.13.0 lib/couch_potato/persistence/active_model_compliance.rb
couch_potato-1.12.1 lib/couch_potato/persistence/active_model_compliance.rb
couch_potato-1.12.0 lib/couch_potato/persistence/active_model_compliance.rb
couch_potato-1.11.0 lib/couch_potato/persistence/active_model_compliance.rb
couch_potato-1.10.1 lib/couch_potato/persistence/active_model_compliance.rb
couch_potato-1.10.0 lib/couch_potato/persistence/active_model_compliance.rb
couch_potato-1.9.0 lib/couch_potato/persistence/active_model_compliance.rb
couch_potato-1.7.1 lib/couch_potato/persistence/active_model_compliance.rb
couch_potato-1.7.0 lib/couch_potato/persistence/active_model_compliance.rb
couch_potato-1.6.5 lib/couch_potato/persistence/active_model_compliance.rb
couch_potato-1.6.4 lib/couch_potato/persistence/active_model_compliance.rb
couch_potato-1.6.3 lib/couch_potato/persistence/active_model_compliance.rb
couch_potato-1.4.0 lib/couch_potato/persistence/active_model_compliance.rb
couch_potato-1.3.0 lib/couch_potato/persistence/active_model_compliance.rb
couch_potato-1.2.0 lib/couch_potato/persistence/active_model_compliance.rb