Sha256: 237c17b227b86d9554ad4cbb1e7486c7289ea764fc54344b623bf597f62db530

Contents?: true

Size: 1.45 KB

Versions: 3

Compression:

Stored size: 1.45 KB

Contents

# rubocop:disable all
#
module Familia
  # InstanceMethods - Module containing instance-level methods for Familia
  #
  # This module is included in classes that include Familia, providing
  # instance-level functionality for Redis operations and object management.
  #
  class Horreum

    # Utils - Module containing utility methods for Familia::Horreum (InstanceMethods)
    #
    module Utils

      def redisuri(suffix = nil)
        u = Familia.redisuri(self.class.uri) # returns URI::Redis
        u.db = db if db # override the db if we have one
        u.key = rediskey(suffix)
        u
      end

      # +suffix+ is the value to be used at the end of the redis key
      # (e.g. `customer:customer_id:scores` would have `scores` as the suffix
      # and `customer_id` would have been the identifier in that case).
      #
      # identifier is the value that distinguishes this object from others.
      # Whether this is a Horreum or RedisType object, the value is taken
      # from the `identifier` method).
      #
      def rediskey(suffix = nil, ignored = nil)
        raise Familia::NoIdentifier, "No identifier for #{self.class}" if identifier.to_s.empty?
        suffix ||= self.suffix # use the instance method to get the default suffix
        self.class.rediskey identifier, suffix
      end

      def join(*args)
        Familia.join(args.map { |field| send(field) })
      end
    end

    include Utils # these become Horreum instance methods
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
familia-1.1.0.pre.rc1 lib/familia/horreum/utils.rb
familia-1.0.0.pre.rc7 lib/familia/horreum/utils.rb
familia-1.0.0.pre.rc6 lib/familia/horreum/utils.rb