Class: Zabbirc::Setting

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeSetting

Returns a new instance of Setting.



9
10
11
# File 'lib/zabbirc/setting.rb', line 9

def initialize
  @options = 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
  @options[name] ||= value
end

#get(name) ⇒ Object



25
26
27
# File 'lib/zabbirc/setting.rb', line 25

def get name
  @options[name]
end

#restore(stored_options) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/zabbirc/setting.rb', line 13

def restore stored_options
  stored_options = ActiveSupport::HashWithIndifferentAccess.new stored_options
  unknown_keys = stored_options.keys - DEFAULTS.keys
  stored_options.delete_if{|k,_v| unknown_keys.include? k }
  stored_options.merge DEFAULTS.deep_dup
  @options = stored_options
end

#set(name, value) ⇒ Object



21
22
23
# File 'lib/zabbirc/setting.rb', line 21

def set name, value
  @options[name] = value
end

#to_hashObject



39
40
41
# File 'lib/zabbirc/setting.rb', line 39

def to_hash
  @options.to_hash.deep_dup
end

#to_sObject



33
34
35
36
37
# File 'lib/zabbirc/setting.rb', line 33

def to_s
  @options.collect do |k, v|
    "#{k}: #{v}"
  end.join(", ")
end