Class: Courier::OwnerSetting

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/courier/owner_setting.rb

Instance Method Summary collapse

Instance Method Details

#disabled?(template, service, args = {}) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/courier/owner_setting.rb', line 67

def disabled?(template, service, args={})
  get(template, service)==:disabled
end

#get(template, service) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/courier/owner_setting.rb', line 50

def get(template, service)
  service = Courier.service(service)
  template = Courier.template(template)
  default = template.get(service)
  return :disabled if default==:disabled
  val = settings_of_template(template)[service.name]
  val || default
end

#off?(template, service, args = {}) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/courier/owner_setting.rb', line 63

def off?(template, service, args={})
  get(template, service)==:off
end

#on?(template, service, args = {}) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/courier/owner_setting.rb', line 59

def on?(template, service, args={})
  get(template, service)==:on
end

#set(template, service, val = nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/courier/owner_setting.rb', line 25

def set(template, service, val=nil)
  service = Courier.service(service)
  raise 'Cant use value as argument when block given' if block_given? and val
  val = yield if block_given?
  if val.blank?
    settings_of_template(template).delete(service.name)
    nil
  else
    # TODO validate setted value
    settings_of_template(template)[service.name] = val.to_sym
  end
end

#set!(template, service, val = nil) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/courier/owner_setting.rb', line 38

def set!(template, service, val=nil)
  if block_given?
    set template, service do
      yield
    end
  else
    set(template, service, val)
  end
  save!
end

#settings_of_template(template) ⇒ Object



20
21
22
23
# File 'lib/courier/owner_setting.rb', line 20

def settings_of_template(template)
  template = Courier.template(template)
  settings[template.name]||={}
end