Sha256: b3f8b561f6a7c82f57578e9d6e4614d240ec92d41ca9119aabf1f9eab8559aee

Contents?: true

Size: 1.28 KB

Versions: 4

Compression:

Stored size: 1.28 KB

Contents

module Gush
  class Configuration
    attr_accessor :concurrency, :namespace, :redis_url, :ttl, :locking_duration, :polling_interval

    def self.from_json(json)
      new(Gush::JSON.decode(json, symbolize_keys: true))
    end

    def initialize(hash = {})
      self.concurrency      = hash.fetch(:concurrency, 5)
      self.namespace        = hash.fetch(:namespace, 'gush')
      self.redis_url        = hash.fetch(:redis_url, 'redis://localhost:6379')
      self.gushfile         = hash.fetch(:gushfile, 'Gushfile')
      self.ttl              = hash.fetch(:ttl, -1)
      self.locking_duration = hash.fetch(:locking_duration, 2) # how long you want to wait for the lock to be released, in seconds
      self.polling_interval = hash.fetch(:polling_internal, 0.3) # how long the polling interval should be, in seconds
    end

    def gushfile=(path)
      @gushfile = Pathname(path)
    end

    def gushfile
      @gushfile.realpath if @gushfile.exist?
    end

    def to_hash
      {
        concurrency:      concurrency,
        namespace:        namespace,
        redis_url:        redis_url,
        ttl:              ttl,
        locking_duration: locking_duration,
        polling_interval: polling_interval
      }
    end

    def to_json
      Gush::JSON.encode(to_hash)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gush-4.1.0 lib/gush/configuration.rb
gush-4.0.0 lib/gush/configuration.rb
gush-3.0.0 lib/gush/configuration.rb
gush-2.1.0 lib/gush/configuration.rb