Module: Qwirk::BaseWorker::ClassMethods

Defined in:
lib/qwirk/base_worker.rb

Instance Method Summary collapse

Instance Method Details

#bean_attrsObject



15
16
17
# File 'lib/qwirk/base_worker.rb', line 15

def bean_attrs
  @bean_attrs ||= []
end

#config_accessor(name, type, description, default_value = nil) ⇒ Object

config_accessor :sleep_time, :float, ‘Number of seconds to sleep between messages’, 5



20
21
22
# File 'lib/qwirk/base_worker.rb', line 20

def config_accessor(name, type, description, default_value=nil)
  self.bean_attrs << [:bean_attr_accessor, name, type, description, default_value]
end

#config_reader(name, type, description, default_value = nil) ⇒ Object



24
25
26
# File 'lib/qwirk/base_worker.rb', line 24

def config_reader(name, type, description, default_value=nil)
  self.bean_attrs << [:bean_attr_reader, name, type, description, default_value]
end

#config_writer(name, type, description, default_value = nil) ⇒ Object



28
29
30
# File 'lib/qwirk/base_worker.rb', line 28

def config_writer(name, type, description, default_value=nil)
  self.bean_attrs << [:bean_attr_writer, name, type, description, default_value]
end

#default_nameObject



10
11
12
13
# File 'lib/qwirk/base_worker.rb', line 10

def default_name
  name = self.name.sub(/Worker$/, '')
  name.sub(/::/, '_')
end

#define_configs(configs) ⇒ Object



32
33
34
# File 'lib/qwirk/base_worker.rb', line 32

def define_configs(configs)
  @configs = configs
end

#each_config(worker_config_class, &block) ⇒ Object

For each configuration of this worker, yield the name, extended_worker_config_class (the adapters worker_config extended with this class’s config attributes), and the default configuration values.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/qwirk/base_worker.rb', line 38

def each_config(worker_config_class, &block)
  # Configs are either defined with a define_configs call or default to a single instance with default_config
  default_config = worker_config_class.initial_default_config
  extended_worker_config_class = Class.new(worker_config_class)
  self.bean_attrs.each do |args|
    attr_method, name, type, description, default_value = args
    extended_worker_config_class.send(attr_method, name, type, description, :config_item => true)
    default_config[name.to_sym] = default_value
  end
  if @configs
    @configs.each do |name, config|
      yield name, extended_worker_config_class, default_config.merge(config)
    end
  else
    yield default_name, extended_worker_config_class, default_config
  end
end