Sha256: 0d724cf275a65239e875597625e11e5a150ad1732d91b66b80726ca979f2eb7a

Contents?: true

Size: 894 Bytes

Versions: 14

Compression:

Stored size: 894 Bytes

Contents

module CassandraObject
  module Identity
    class NaturalKeyFactory < AbstractKeyFactory
      class NaturalKey
        include Key

        attr_reader :value

        def initialize(value)
          @value = value
        end

        def to_s
          value
        end

        def to_param
          value
        end

        def ==(other)
          other.is_a?(NaturalKey) && other.value == value
        end

        def eql?(other)
          other == self
        end
      end

      attr_reader :attributes, :separator

      def initialize(options)
        @attributes = [*options[:attributes]]
        @separator  = options[:separator] || "-"
      end

      def next_key(object)
        NaturalKey.new(attributes.map { |a| object.attributes[a.to_s] }.join(separator))
      end

      def parse(paramized_key)
        NaturalKey.new(paramized_key)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
gotime-cassandra_object-2.7.2 lib/cassandra_object/identity/natural_key_factory.rb
gotime-cassandra_object-2.7.1 lib/cassandra_object/identity/natural_key_factory.rb
gotime-cassandra_object-2.7.0 lib/cassandra_object/identity/natural_key_factory.rb
gotime-cassandra_object-2.6.4 lib/cassandra_object/identity/natural_key_factory.rb
gotime-cassandra_object-2.6.3 lib/cassandra_object/identity/natural_key_factory.rb
gotime-cassandra_object-2.6.2 lib/cassandra_object/identity/natural_key_factory.rb
gotime-cassandra_object-2.6.1 lib/cassandra_object/identity/natural_key_factory.rb
gotime-cassandra_object-2.6.0 lib/cassandra_object/identity/natural_key_factory.rb
gotime-cassandra_object-2.5.0 lib/cassandra_object/identity/natural_key_factory.rb
gotime-cassandra_object-2.4.2 lib/cassandra_object/identity/natural_key_factory.rb
gotime-cassandra_object-2.4.1 lib/cassandra_object/identity/natural_key_factory.rb
gotime-cassandra_object-2.4.0 lib/cassandra_object/identity/natural_key_factory.rb
gotime-cassandra_object-2.3.6 lib/cassandra_object/identity/natural_key_factory.rb
gotime-cassandra_object-2.3.5 lib/cassandra_object/identity/natural_key_factory.rb