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(slug) ⇒ Local

Returns a new instance of Local.



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

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

  self['name']       = meta['name']       ||= slug
  self['slug']       = meta['slug']       ||= slug
  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.



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

def avail
  @avail
end

#slugObject (readonly)

Returns the value of attribute slug.



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

def slug
  @slug
end

Instance Method Details

#delete!Object



43
44
45
46
47
48
49
# File 'lib/mandrill_template/template.rb', line 43

def delete!
  dir_name = File.join(templates_directory, slug)
  puts dir_name
  if Dir.exists?(dir_name)
    FileUtils.rm_rf(dir_name)
  end
end

#load_data(slug) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/mandrill_template/template.rb', line 28

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

#templates_directoryObject



24
25
26
# File 'lib/mandrill_template/template.rb', line 24

def templates_directory
  MandrillClient.templates_directory
end