Sha256: 05dc3b6247d9cce1844f9a53e157ace4a17b140bc65f9791ee608767cfe6a3a4

Contents?: true

Size: 448 Bytes

Versions: 13

Compression:

Stored size: 448 Bytes

Contents

module NinjaModel
  module Identity
    extend ActiveSupport::Concern

    included do
      class_attribute :primary_key
      self.primary_key = :id
      undef_method(:id) if method_defined?(:id)
    end

    def to_model
      self
    end

    def to_param
      send(self.class.primary_key).to_s if persisted?
    end

    def to_key
      key = nil
      key = send(self.class.primary_key) if persisted?
      [key] if key
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ninja-model-1.0.5 lib/ninja_model/identity.rb
ninja-model-1.0.4 lib/ninja_model/identity.rb
ninja-model-1.0.3 lib/ninja_model/identity.rb
ninja-model-1.0.2 lib/ninja_model/identity.rb
ninja-model-1.0.1 lib/ninja_model/identity.rb
ninja-model-1.0.0 lib/ninja_model/identity.rb
ninja-model-0.9.6 lib/ninja_model/identity.rb
ninja-model-0.9.5 lib/ninja_model/identity.rb
ninja-model-0.9.4 lib/ninja_model/identity.rb
ninja-model-0.9.3 lib/ninja_model/identity.rb
ninja-model-0.9.2 lib/ninja_model/identity.rb
ninja-model-0.9.1 lib/ninja_model/identity.rb
ninja-model-0.9.0 lib/ninja_model/identity.rb