Class: Sprig::Reap::FileAttribute
- Inherits:
-
Object
- Object
- Sprig::Reap::FileAttribute
- Defined in:
- lib/sprig/reap/file_attribute.rb
Defined Under Namespace
Classes: LocalFile
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Returns the value of attribute input.
Instance Method Summary collapse
- #existing_location ⇒ Object
- #file ⇒ Object
- #file? ⇒ Boolean
- #filename ⇒ Object
-
#initialize(input) ⇒ FileAttribute
constructor
A new instance of FileAttribute.
- #local_file ⇒ Object
- #target_folder ⇒ Object
- #target_location ⇒ Object
Constructor Details
#initialize(input) ⇒ FileAttribute
Returns a new instance of FileAttribute.
5 6 7 |
# File 'lib/sprig/reap/file_attribute.rb', line 5 def initialize(input) @input = input end |
Instance Attribute Details
#input ⇒ Object (readonly)
Returns the value of attribute input.
3 4 5 |
# File 'lib/sprig/reap/file_attribute.rb', line 3 def input @input end |
Instance Method Details
#existing_location ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/sprig/reap/file_attribute.rb', line 17 def existing_location begin input.url if input.url.present? && open(input.url).is_a?(Tempfile) rescue input.path end end |
#file ⇒ Object
9 10 11 |
# File 'lib/sprig/reap/file_attribute.rb', line 9 def file local_file if file? end |
#file? ⇒ Boolean
13 14 15 |
# File 'lib/sprig/reap/file_attribute.rb', line 13 def file? input.is_a? CarrierWave::Uploader::Base end |
#filename ⇒ Object
25 26 27 |
# File 'lib/sprig/reap/file_attribute.rb', line 25 def filename File.basename(existing_location) end |
#local_file ⇒ Object
41 42 43 |
# File 'lib/sprig/reap/file_attribute.rb', line 41 def local_file @local_file ||= LocalFile.new(existing_location, target_location) end |
#target_folder ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/sprig/reap/file_attribute.rb', line 29 def target_folder @target_folder ||= begin path = Rails.root.join('db', 'seeds', Sprig::Reap.target_env, 'files') FileUtils.mkdir_p(path) path end end |
#target_location ⇒ Object
37 38 39 |
# File 'lib/sprig/reap/file_attribute.rb', line 37 def target_location target_folder.join(filename) end |