Class: Dakwak::Configurator
- Inherits:
-
Object
- Object
- Dakwak::Configurator
- Includes:
- Logger
- Defined in:
- lib/dakwak/configurator.rb
Class Attribute Summary collapse
-
.subs ⇒ Object
readonly
Returns the value of attribute subs.
Class Method Summary collapse
Instance Method Summary collapse
- #consume(json_feed) ⇒ Object
-
#initialize ⇒ Configurator
constructor
include Silencable.
Methods included from Logger
included, #log, #log_indent, #log_indent_dec, #log_indent_inc, #logging_context
Methods included from Silencable
Constructor Details
#initialize ⇒ Configurator
include Silencable
23 24 25 26 27 28 29 |
# File 'lib/dakwak/configurator.rb', line 23 def initialize logging_context("Configurator") @@subs ||= {} @@opts ||= {} super() end |
Class Attribute Details
.subs ⇒ Object (readonly)
Returns the value of attribute subs.
8 9 10 |
# File 'lib/dakwak/configurator.rb', line 8 def subs @subs end |
Class Method Details
.subscribe(context, configurable) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/dakwak/configurator.rb', line 10 def subscribe(context, configurable) if not configurable.respond_to?("set_option") raise "Subscribing as a configurable must respond_to method 'set_option'" end @@subs ||= {} @@subs[context] ||= []; @@subs[context] << configurable end |
Instance Method Details
#consume(json_feed) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/dakwak/configurator.rb', line 31 def consume(json_feed) begin cfg = JSON.parse(json_feed) rescue JSON::ParserError => e log_error "Unable to parse JSON configuration feed; #{e.}" return nil end cfg.each_pair { |ctx, | if not @@subs[ctx] or @@subs[ctx].empty? then log_warn "Context #{ctx} has no subscribers, ignoring." unless silent? next end log_debug "Configuring context #{ctx} (#{@@subs[ctx].size} subscribers)" unless silent? .each_pair { |name, val| @@subs[ctx] ||= [] @@subs[ctx].each { |configurable| configurable.set_option(name, val) } } } true end |