Class: Zabbirc::Setting
- Inherits:
-
Object
- Object
- Zabbirc::Setting
- Defined in:
- lib/zabbirc/setting.rb
Constant Summary collapse
- DEFAULTS =
ActiveSupport::HashWithIndifferentAccess.new({ notify: true, notify_recoveries: true, primary_channel: nil, events_priority: Zabbirc.config.default_events_priority, host_groups: ActiveSupport::HashWithIndifferentAccess.new })
Instance Method Summary collapse
- #fetch(name, value, *options) ⇒ Object
- #get(name, *options) ⇒ Object
-
#initialize ⇒ Setting
constructor
A new instance of Setting.
- #restore(stored_options) ⇒ Object
- #set(name, value, *options) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
Instance Method Details
#fetch(name, value, *options) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/zabbirc/setting.rb', line 41 def fetch name, value, * host_group_id = parse_host_group_id() if host_group_id if (host_group_id)[name].nil? set_with_host_group name, value, host_group_id else get name, host_group_id: host_group_id end else @options[name] ||= value end end |
#get(name, *options) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/zabbirc/setting.rb', line 32 def get name, * host_group_id = parse_host_group_id() if host_group_id first_not_nil((host_group_id)[name], @options[name]) else @options[name] end end |
#restore(stored_options) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/zabbirc/setting.rb', line 16 def restore = ActiveSupport::HashWithIndifferentAccess.new unknown_keys = .keys - DEFAULTS.keys .delete_if{|k,_v| unknown_keys.include? k } @options = DEFAULTS.deep_dup.merge() end |
#set(name, value, *options) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/zabbirc/setting.rb', line 23 def set name, value, * host_group_id = parse_host_group_id() if host_group_id set_with_host_group name, value, host_group_id else @options[name] = value end end |
#to_hash ⇒ Object
55 56 57 |
# File 'lib/zabbirc/setting.rb', line 55 def to_hash @options.to_hash.deep_dup end |