class Sprig::Reap::FileAttribute
Attributes
input[R]
Public Class Methods
new(input)
click to toggle source
# File lib/sprig/reap/file_attribute.rb, line 5 def initialize(input) @input = input end
Public Instance Methods
existing_location()
click to toggle source
# 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()
click to toggle source
# File lib/sprig/reap/file_attribute.rb, line 9 def file local_file if file? end
file?()
click to toggle source
# File lib/sprig/reap/file_attribute.rb, line 13 def file? defined?(::CarrierWave) && input.is_a?(::CarrierWave::Uploader::Base) end
filename()
click to toggle source
# File lib/sprig/reap/file_attribute.rb, line 25 def filename File.basename(existing_location) end
local_file()
click to toggle source
# File lib/sprig/reap/file_attribute.rb, line 41 def local_file @local_file ||= LocalFile.new(existing_location, target_location) end
target_folder()
click to toggle source
# 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()
click to toggle source
# File lib/sprig/reap/file_attribute.rb, line 37 def target_location target_folder.join(filename) end