Sha256: 122ceeb6dbfed5b578835975877c52a5b3f6214693bd7b2cf124d0968ce465d4

Contents?: true

Size: 1.58 KB

Versions: 1

Compression:

Stored size: 1.58 KB

Contents

module Mongo
  class Lock
    class Configuration

      attr_accessor :connections
      attr_accessor :limit
      attr_accessor :timeout_in
      attr_accessor :frequency
      attr_accessor :expire_in
      attr_accessor :owner
      attr_accessor :raise

      def initialize defaults, options, &block
        options = defaults.merge(options)
        options[:collections] ||= {}
        if options[:collection]
          options[:collections][:default] = options[:collection]
        end
        options.each_pair do |key,value|
          self.send(:"#{key}=",value)
        end
        yield self if block_given?
      end

      def collection= collection
        collections[:default] = collection
      end

      def collection collection = :default
        collection = collection.to_sym if collection.is_a? String
        if collection.is_a? Symbol
          collections[collection]
        else
          collection
        end
      end

      def collections= collections
        @collections = collections
      end

      def set_collections_keep_default collections
        collections[:default] = @collections[:default]
        @collections = collections
      end

      def collections
        @collections ||= {}
      end

      def to_hash
        {
          timeout_in: timeout_in,
          limit: limit,
          frequency: frequency,
          expire_in: expire_in,
          owner: owner,
          raise: raise
        }
      end

      def owner
        if @owner.is_a? Proc
          @owner.call.to_s
        else
          @owner.to_s
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongo-lock-1.1.0 lib/mongo-lock/configuration.rb