Sha256: 2929d15e0484f1ed49cec3562edccffe95d5cd305b1fe285dcd0026cb07f6163

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

require 'yajl'

module Gush
  class Configuration
    attr_accessor :concurrency, :namespace, :redis_url, :environment

    def self.from_json(json)
      new(Yajl::Parser.parse(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.rb')
      self.environment = hash.fetch(:environment, 'development')
    end

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

    def gushfile
      raise Thor::Error, "#{@gushfile} not found, please add it to your project".colorize(:red) unless @gushfile.exist?
      @gushfile.realpath
    end

    def to_hash
      {
        concurrency: concurrency,
        namespace:   namespace,
        redis_url:   redis_url,
        environment: environment,
        gushfile:    gushfile.to_path
      }
    end

    def to_json
      Yajl::Encoder.new.encode(to_hash)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gush-0.0.1 lib/gush/configuration.rb