Class: Dayvan::Attachment
- Inherits:
-
Object
- Object
- Dayvan::Attachment
- Defined in:
- lib/dayvan/attachment.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #content_type ⇒ Object
- #data ⇒ Object
-
#initialize(path) ⇒ Attachment
constructor
A new instance of Attachment.
- #name ⇒ Object
- #signature ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(path) ⇒ Attachment
Returns a new instance of Attachment.
26 27 28 |
# File 'lib/dayvan/attachment.rb', line 26 def initialize(path) self.path = path end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
24 25 26 |
# File 'lib/dayvan/attachment.rb', line 24 def path @path end |
Class Method Details
.all(root) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/dayvan/attachment.rb', line 7 def self.all(root) root.exist? && Dir[root.join('**/**')]. reject {|f| File.directory?(f)}. # Allows symlinks inject({}) {|all, f| = new(f) all[.path.relative_path_from(root)] = all } end |
.signatures ⇒ Object
17 18 19 20 21 22 |
# File 'lib/dayvan/attachment.rb', line 17 def self.signatures all.inject({}) do |signatures, (path, )| signatures[path] = .signature signatures end end |
Instance Method Details
#content_type ⇒ Object
30 31 32 |
# File 'lib/dayvan/attachment.rb', line 30 def content_type (MIME::Types.of(path.to_s).first || 'text/plain').to_s end |
#data ⇒ Object
34 35 36 |
# File 'lib/dayvan/attachment.rb', line 34 def data Base64.encode64(path.read).delete("\s\n") end |
#name ⇒ Object
38 39 40 |
# File 'lib/dayvan/attachment.rb', line 38 def name path.basename('*.*') end |
#signature ⇒ Object
46 47 48 |
# File 'lib/dayvan/attachment.rb', line 46 def signature Digest::MD5.hexdigest(data) end |
#to_json ⇒ Object
50 51 52 |
# File 'lib/dayvan/attachment.rb', line 50 def to_json {:content_type => content_type, :data => data}.to_json end |