class RemoteFiles::File
Attributes
Public Class Methods
Source
# File lib/remote_files/file.rb, line 31 def self.from_url(url) RemoteFiles.default_configuration.file_from_url(url) end
Source
# File lib/remote_files/file.rb, line 5 def initialize(identifier, options = {}) known_keys = [:identifier, :stored_in, :content_type, :configuration, :content, :populate_stored_in, :last_update_ts, :errors] known_keys.each do |key| options[key] ||= options.delete(key.to_s) end @identifier = identifier @stored_in = (options[:stored_in] || []).map(&:to_sym) # TODO: Refactor so that there are two classes: `File` and `FileCopy` @content = options.delete(:content) @last_update_ts = options[:last_update_ts] || Time.now @content_type = options[:content_type] @configuration = RemoteFiles::CONFIGURATIONS[(options[:configuration] || :default).to_sym] @logger = options[:logger] @populate_stored_in = options[:populate_stored_in] @errors = options[:errors] @options = options end
Public Instance Methods
Source
# File lib/remote_files/file.rb, line 75 def current_url prioritized_stores = configuration.stores.map(&:identifier) & @stored_in return nil if prioritized_stores.empty? url(prioritized_stores[0]) end
Source
# File lib/remote_files/file.rb, line 116 def delete begin delete! true rescue RemoteFiles::Error => e false end end
Source
# File lib/remote_files/file.rb, line 112 def delete! configuration.delete!(self) end
Source
# File lib/remote_files/file.rb, line 125 def delete_now!(parallel: false) configuration.delete_now!(self, parallel: parallel) end
Source
# File lib/remote_files/file.rb, line 27 def logger @logger ||= configuration ? configuration.logger : RemoteFiles.logger end
Source
# File lib/remote_files/file.rb, line 23 def logger=(logger) @logger = logger end
Source
# File lib/remote_files/file.rb, line 65 def missing_stores configuration.stores - stores end
Source
# File lib/remote_files/file.rb, line 35 def options @options.merge( :identifier => identifier, :stored_in => stored_in, :content_type => content_type, :configuration => configuration.name, :populate_stored_in => populate_stored_in ) end
Source
# File lib/remote_files/file.rb, line 61 def read_delete_only_stores stores.select(&:read_delete_only?) end
Source
# File lib/remote_files/file.rb, line 57 def read_write_stores stores.reject {|s| s.read_only? || s.read_delete_only? } end
Source
# File lib/remote_files/file.rb, line 83 def retrieve! stores.each do |store| begin file = store.retrieve!(identifier) next unless file @content = file.content @content_type = file.content_type # :populate_stored_in is a boolean @stored_in = file.stored_in if @populate_stored_in return true rescue Error => e end end raise NotFoundError end
Source
# File lib/remote_files/file.rb, line 100 def store! configuration.store!(self) end
Source
# File lib/remote_files/file.rb, line 104 def store_once! configuration.store_once!(self) end
Source
# File lib/remote_files/file.rb, line 49 def stored_everywhere? missing_stores.empty? end
Source
# File lib/remote_files/file.rb, line 53 def stores @stored_in.map { |store_id| configuration.lookup_store(store_id) } end
Source
# File lib/remote_files/file.rb, line 108 def synchronize! configuration.synchronize!(self) end
Source
# File lib/remote_files/file.rb, line 69 def url(store_identifier = nil) store = store_identifier ? configuration.lookup_store(store_identifier) : configuration.primary_store return nil unless store store.url(identifier) end