Class: MandrillTemplate::Local
- Inherits:
-
Hash
- Object
- Hash
- MandrillTemplate::Local
- Defined in:
- lib/mandrill_template/template.rb
Instance Attribute Summary collapse
-
#avail ⇒ Object
readonly
Returns the value of attribute avail.
-
#slug ⇒ Object
readonly
Returns the value of attribute slug.
Instance Method Summary collapse
- #delete! ⇒ Object
-
#initialize(slug) ⇒ Local
constructor
A new instance of Local.
- #load_data(slug) ⇒ Object
- #templates_directory ⇒ Object
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 , code, text = load_data(slug) self['name'] = ['name'] ||= slug self['slug'] = ['slug'] ||= slug self['from_email'] = ['from_email'] ||= nil self['from_name'] = ['from_name'] ||= nil self['subject'] = ['subject'] ||= nil self['labels'] = ['labels'] ||= [] self['code'] = code ||= nil self['text'] = text ||= nil end |
Instance Attribute Details
#avail ⇒ Object (readonly)
Returns the value of attribute avail.
7 8 9 |
# File 'lib/mandrill_template/template.rb', line 7 def avail @avail end |
#slug ⇒ Object (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_directory ⇒ Object
24 25 26 |
# File 'lib/mandrill_template/template.rb', line 24 def templates_directory MandrillClient.templates_directory end |