Class: Courier::Template::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/courier/template/base.rb

Constant Summary collapse

AvailableValues =
[:on, :off, :disabled]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Base

Returns a new instance of Base.



8
9
10
11
# File 'lib/courier/template/base.rb', line 8

def initialize(args)
  self.name = args[:name].to_sym or raise 'no template name defined'
  self.defaults={}
end

Instance Attribute Details

#defaultsObject

Returns the value of attribute defaults.



6
7
8
# File 'lib/courier/template/base.rb', line 6

def defaults
  @defaults
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/courier/template/base.rb', line 6

def name
  @name
end

Instance Method Details

#get(service) ⇒ Object



19
20
21
22
23
24
# File 'lib/courier/template/base.rb', line 19

def get(service)
  service = Courier.service(service) if service.is_a?(Symbol)
  name = service.name.to_sym
  raise "Not defined default value for #{service} in template #{self}" unless defaults.has_key? name
  defaults[name]
end

#get_text(service, args) ⇒ Object



13
14
15
16
17
# File 'lib/courier/template/base.rb', line 13

def get_text(service, args)
  args[:scope]=[:courier, :services, service.to_s, :templates] unless args[:scope]
  args[:cascade]=true unless args.has_key? :cascade
  I18n::translate(name, args )
end

#keyObject



39
40
41
# File 'lib/courier/template/base.rb', line 39

def key
  name
end

#set(service, val) ⇒ Object



26
27
28
29
# File 'lib/courier/template/base.rb', line 26

def set(service, val)
  service = Courier.service(service) if service.is_a?(Symbol)
  defaults[service.name.to_sym] = check_val(val)
end

#to_labelObject



35
36
37
# File 'lib/courier/template/base.rb', line 35

def to_label
  I18n::translate(name, :scope=>[:courier,:templates] )
end

#to_sObject



31
32
33
# File 'lib/courier/template/base.rb', line 31

def to_s
  name.to_s
end