Class: Zabbirc::Setting
- Inherits:
-
Object
- Object
- Zabbirc::Setting
- Defined in:
- lib/zabbirc/setting.rb
Constant Summary collapse
- DEFAULTS =
ActiveSupport::HashWithIndifferentAccess.new({ notify: true, primary_channel: nil, events_priority: Zabbirc.config.default_events_priority })
Instance Method Summary collapse
- #fetch(name, value) ⇒ Object
- #get(name) ⇒ Object
-
#initialize ⇒ Setting
constructor
A new instance of Setting.
- #restore(stored_options) ⇒ Object
- #set(name, value) ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Setting
Returns a new instance of Setting.
9 10 11 |
# File 'lib/zabbirc/setting.rb', line 9 def initialize = ActiveSupport::HashWithIndifferentAccess.new DEFAULTS.deep_dup end |
Instance Method Details
#fetch(name, value) ⇒ Object
29 30 31 |
# File 'lib/zabbirc/setting.rb', line 29 def fetch name, value [name] ||= value end |
#get(name) ⇒ Object
25 26 27 |
# File 'lib/zabbirc/setting.rb', line 25 def get name [name] end |
#restore(stored_options) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/zabbirc/setting.rb', line 13 def restore = ActiveSupport::HashWithIndifferentAccess.new unknown_keys = .keys - DEFAULTS.keys .delete_if{|k,_v| unknown_keys.include? k } .merge DEFAULTS.deep_dup = end |
#set(name, value) ⇒ Object
21 22 23 |
# File 'lib/zabbirc/setting.rb', line 21 def set name, value [name] = value end |
#to_hash ⇒ Object
39 40 41 |
# File 'lib/zabbirc/setting.rb', line 39 def to_hash .to_hash.deep_dup end |
#to_s ⇒ Object
33 34 35 36 37 |
# File 'lib/zabbirc/setting.rb', line 33 def to_s .collect do |k, v| "#{k}: #{v}" end.join(", ") end |