Class: MandrillTemplate::Local

Inherits:
Hash
  • Object
show all
Defined in:
lib/mandrill_template/template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Local

Returns a new instance of Local.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/mandrill_template/template.rb', line 8

def initialize(name)
  @name       = name
  meta, code, text = load_data(name)

  self['name']       = name
  self['slug']       = meta['slug']       ||= name
  self['from_email'] = meta['from_email'] ||= nil
  self['from_name']  = meta['from_name']  ||= nil
  self['subject']    = meta['subject']    ||= nil
  self['labels']     = meta['labels']     ||= []

  self['code']       = code               ||= nil
  self['text']       = text               ||= nil
end

Instance Attribute Details

#availObject (readonly)

Returns the value of attribute avail.



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

def avail
  @avail
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#load_data(name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mandrill_template/template.rb', line 23

def load_data(name)
  if Dir.exists?(File.join("templates", name))
    @avail = true
    code = File.read(File.join("templates", name, "code"))
    text = File.read(File.join("templates", name, "text"))
    [
      YAML.load_file(File.join("templates", name, "metadata.yml")),
      code.empty? ? nil : code,
      text.empty? ? nil : text
    ]
  else
    [{}, nil, nil]
  end
end