Sha256: b095c5ff469a13566f74a07e0dbea3b7d0b68796f690d25d88ee6c3e8e0692de

Contents?: true

Size: 886 Bytes

Versions: 1

Compression:

Stored size: 886 Bytes

Contents

require 'active_support/concern'

module Ripple
  module Document
    module Key
      extend ActiveSupport::Concern

      module ClassMethods
        # Defines the key to be derived from a property.
        # @param [String,Symbol] prop the property to derive the key from
        def key_on(prop)
          class_eval <<-CODE
          def key
            #{prop}.to_s
          end
          def key=(value)
            self.#{prop} = value
          end
          def key_attr
            :#{prop}
          end          
          CODE
        end
      end
      
      module InstanceMethods
        # Reads the key for this Document.
        def key
          @key
        end
        
        # Sets the key for this Document.
        def key=(value)
          @key = value.to_s
        end

        def key_attr
          :key
        end        
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
seomoz-ripple-1.0.0.pre lib/ripple/document/key.rb