Class: LetterOpenerWeb::Letter
- Inherits:
-
Object
- Object
- LetterOpenerWeb::Letter
- Defined in:
- app/models/letter_opener_web/letter.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#sent_at ⇒ Object
readonly
Returns the value of attribute sent_at.
Class Method Summary collapse
Instance Method Summary collapse
- #attachments ⇒ Object
- #default_style ⇒ Object
- #delete ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(params) ⇒ Letter
constructor
A new instance of Letter.
- #plain_text ⇒ Object
- #rich_text ⇒ Object
- #to_param ⇒ Object
Constructor Details
#initialize(params) ⇒ Letter
Returns a new instance of Letter.
24 25 26 27 |
# File 'app/models/letter_opener_web/letter.rb', line 24 def initialize(params) @id = params.fetch(:id) @sent_at = params[:sent_at] end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'app/models/letter_opener_web/letter.rb', line 7 def id @id end |
#sent_at ⇒ Object (readonly)
Returns the value of attribute sent_at.
7 8 9 |
# File 'app/models/letter_opener_web/letter.rb', line 7 def sent_at @sent_at end |
Class Method Details
.destroy_all ⇒ Object
20 21 22 |
# File 'app/models/letter_opener_web/letter.rb', line 20 def self.destroy_all FileUtils.rm_rf(letters_location) end |
.find(id) ⇒ Object
16 17 18 |
# File 'app/models/letter_opener_web/letter.rb', line 16 def self.find(id) new :id => id end |
.search ⇒ Object
9 10 11 12 13 14 |
# File 'app/models/letter_opener_web/letter.rb', line 9 def self.search letters = Dir.glob("#{letters_location}/*").map do |folder| new :id => File.basename(folder), :sent_at => File.mtime(folder) end letters.sort_by(&:sent_at).reverse end |
Instance Method Details
#attachments ⇒ Object
47 48 49 50 51 |
# File 'app/models/letter_opener_web/letter.rb', line 47 def @attachments ||= Dir["#{base_dir}/attachments/*"].each_with_object({}) do |file, hash| hash[File.basename(file)] = File.(file) end end |
#default_style ⇒ Object
41 42 43 44 45 |
# File 'app/models/letter_opener_web/letter.rb', line 41 def default_style style_exists?('rich') ? 'rich' : 'plain' end |
#delete ⇒ Object
53 54 55 |
# File 'app/models/letter_opener_web/letter.rb', line 53 def delete FileUtils.rm_rf("#{letters_location}/#{self.id}") end |
#exists? ⇒ Boolean
57 58 59 |
# File 'app/models/letter_opener_web/letter.rb', line 57 def exists? File.exists?(base_dir) end |
#plain_text ⇒ Object
29 30 31 |
# File 'app/models/letter_opener_web/letter.rb', line 29 def plain_text @plain_text ||= adjust_link_targets read_file(:plain) end |
#rich_text ⇒ Object
33 34 35 |
# File 'app/models/letter_opener_web/letter.rb', line 33 def rich_text @rich_text ||= adjust_link_targets read_file(:rich) end |
#to_param ⇒ Object
37 38 39 |
# File 'app/models/letter_opener_web/letter.rb', line 37 def to_param id end |