Class: Qs::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/qs.rb

Constant Summary collapse

DEFAULT_ENCODER =
proc{ |payload|         ::JSON.dump(payload)         }
DEFAULT_DECODER =
proc{ |encoded_payload| ::JSON.load(encoded_payload) }
DEFAULT_DISPATCHER_QUEUE_CLASS =
Queue
DEFAULT_DISPATCHER_QUEUE_NAME =
'dispatcher'.freeze
DEFAULT_DISPATCHER_JOB_NAME =
'run_dispatch_job'.freeze
DEFAULT_DISPATCHER_JOB_HANDLER_CLASS_NAME =
DispatcherQueue::RunDispatchJob.to_s.freeze
DEFAULT_REDIS_IP =
'127.0.0.1'.freeze
DEFAULT_REDIS_PORT =
6379.freeze
DEFAULT_REDIS_DB =
0.freeze
DEFAULT_REDIS_NS =
'qs'.freeze
DEFAULT_REDIS_DRIVER =
'ruby'.freeze
DEFAULT_REDIS_TIMEOUT =
1.freeze
DEFAULT_REDIS_SIZE =
4.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/qs.rb', line 131

def initialize
  @encoder         = DEFAULT_ENCODER
  @decoder         = DEFAULT_DECODER
  @timeout         = nil
  @event_publisher = nil

  @dispatcher_queue_class            = DEFAULT_DISPATCHER_QUEUE_CLASS
  @dispatcher_queue_name             = DEFAULT_DISPATCHER_QUEUE_NAME
  @dispatcher_job_name               = DEFAULT_DISPATCHER_JOB_NAME
  @dispatcher_job_handler_class_name = DEFAULT_DISPATCHER_JOB_HANDLER_CLASS_NAME

  @redis_ip      = DEFAULT_REDIS_IP
  @redis_port    = DEFAULT_REDIS_PORT
  @redis_db      = DEFAULT_REDIS_DB
  @redis_ns      = DEFAULT_REDIS_NS
  @redis_driver  = DEFAULT_REDIS_DRIVER
  @redis_timeout = DEFAULT_REDIS_TIMEOUT
  @redis_size    = DEFAULT_REDIS_SIZE
  @redis_url     = nil

  @valid = nil
end

Instance Attribute Details

#decoderObject

Returns the value of attribute decoder.



125
126
127
# File 'lib/qs.rb', line 125

def decoder
  @decoder
end

#dispatcher_job_handler_class_nameObject

Returns the value of attribute dispatcher_job_handler_class_name.



127
128
129
# File 'lib/qs.rb', line 127

def dispatcher_job_handler_class_name
  @dispatcher_job_handler_class_name
end

#dispatcher_job_nameObject

Returns the value of attribute dispatcher_job_name.



127
128
129
# File 'lib/qs.rb', line 127

def dispatcher_job_name
  @dispatcher_job_name
end

#dispatcher_queue_classObject

Returns the value of attribute dispatcher_queue_class.



126
127
128
# File 'lib/qs.rb', line 126

def dispatcher_queue_class
  @dispatcher_queue_class
end

#dispatcher_queue_nameObject

Returns the value of attribute dispatcher_queue_name.



126
127
128
# File 'lib/qs.rb', line 126

def dispatcher_queue_name
  @dispatcher_queue_name
end

#encoderObject

Returns the value of attribute encoder.



125
126
127
# File 'lib/qs.rb', line 125

def encoder
  @encoder
end

#event_publisherObject

Returns the value of attribute event_publisher.



125
126
127
# File 'lib/qs.rb', line 125

def event_publisher
  @event_publisher
end

#redis_dbObject

Returns the value of attribute redis_db.



128
129
130
# File 'lib/qs.rb', line 128

def redis_db
  @redis_db
end

#redis_driverObject

Returns the value of attribute redis_driver.



129
130
131
# File 'lib/qs.rb', line 129

def redis_driver
  @redis_driver
end

#redis_ipObject

Returns the value of attribute redis_ip.



128
129
130
# File 'lib/qs.rb', line 128

def redis_ip
  @redis_ip
end

#redis_nsObject

Returns the value of attribute redis_ns.



128
129
130
# File 'lib/qs.rb', line 128

def redis_ns
  @redis_ns
end

#redis_portObject

Returns the value of attribute redis_port.



128
129
130
# File 'lib/qs.rb', line 128

def redis_port
  @redis_port
end

#redis_sizeObject

Returns the value of attribute redis_size.



129
130
131
# File 'lib/qs.rb', line 129

def redis_size
  @redis_size
end

#redis_timeoutObject

Returns the value of attribute redis_timeout.



129
130
131
# File 'lib/qs.rb', line 129

def redis_timeout
  @redis_timeout
end

#redis_urlObject

Returns the value of attribute redis_url.



129
130
131
# File 'lib/qs.rb', line 129

def redis_url
  @redis_url
end

#timeoutObject

Returns the value of attribute timeout.



125
126
127
# File 'lib/qs.rb', line 125

def timeout
  @timeout
end

Instance Method Details

#redis_connect_hashObject

the keys here should be compatible with HellaRedis connection configs github.com/redding/hella-redis#connection



156
157
158
159
160
161
162
163
164
165
166
# File 'lib/qs.rb', line 156

def redis_connect_hash
  { :ip       => self.redis_ip,
    :port     => self.redis_port,
    :db       => self.redis_db,
    :redis_ns => self.redis_ns,
    :driver   => self.redis_driver,
    :timeout  => self.redis_timeout,
    :size     => self.redis_size,
    :url      => self.redis_url
  }
end

#valid?Boolean

Returns:

  • (Boolean)


168
169
170
# File 'lib/qs.rb', line 168

def valid?
  !!@valid
end

#validate!Object



172
173
174
175
176
177
178
179
# File 'lib/qs.rb', line 172

def validate!
  return @valid if !@valid.nil? # only need to run this once per config

  # set the `redis_url`
  self.redis_url ||= RedisUrl.new(self.redis_ip, self.redis_port, self.redis_db)

  @valid = true
end