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.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name) ⇒ Local
constructor
A new instance of Local.
- #load_data(name) ⇒ Object
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 , code, text = load_data(name) self['name'] = name self['slug'] = ['slug'] ||= name 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.
6 7 8 |
# File 'lib/mandrill_template/template.rb', line 6 def avail @avail end |
#name ⇒ Object (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 |