Module: CloudTempfile
- Defined in:
- lib/cloud_tempfile/config.rb,
lib/cloud_tempfile/engine.rb,
lib/cloud_tempfile/storage.rb,
lib/cloud_tempfile/version.rb,
lib/cloud_tempfile/multi_mime.rb,
lib/cloud_tempfile/cloud_tempfile.rb,
lib/generators/cloud_tempfile/install_generator.rb
Overview
cloud_tempfile/cloud_tempfile.rb
- Author
-
Kevin Bolduc
- Date
-
14-02-24
- Time
-
3:23 PM
Defined Under Namespace
Classes: Config, Engine, InstallGenerator, MultiMime, Storage
Constant Summary collapse
- VERSION =
"1.0.1"
Class Attribute Summary collapse
-
.file_name ⇒ Object
Returns the value of attribute file_name.
-
.file_raw_data ⇒ Object
Returns the value of attribute file_raw_data.
Class Method Summary collapse
-
.clear ⇒ Object
Delete the remote file which are expired if the “config.clean_up” is true and “config.clean_up_older_than” is the amount of seconds it is older than.
- .config ⇒ Object
- .config=(data) ⇒ Object
- .configure {|@config| ... } ⇒ Object
- .enabled? ⇒ Boolean
- .initialize(file_name = nil, file_raw_data = nil) ⇒ Object
- .log(msg) ⇒ Object
- .reset_config! ⇒ Object
-
.stderr ⇒ Object
Log Stub methods.
- .stdout ⇒ Object
- .storage ⇒ Object
- .warn(msg) ⇒ Object
- .with_config(&block) ⇒ Object
-
.write(options = {}) ⇒ File
This action will responsible for persisting the Tempfile == Options [:
file_name
:] The file name to use for the Tempfile [:file_raw_data
:] The raw file data to be persisted [:expiry
:] The expiry is the number of seconds the file will available publicly.
Class Attribute Details
.file_name ⇒ Object
Returns the value of attribute file_name.
10 11 12 |
# File 'lib/cloud_tempfile/cloud_tempfile.rb', line 10 def file_name @file_name end |
.file_raw_data ⇒ Object
Returns the value of attribute file_raw_data.
11 12 13 |
# File 'lib/cloud_tempfile/cloud_tempfile.rb', line 11 def file_raw_data @file_raw_data end |
Class Method Details
.clear ⇒ Object
Delete the remote file which are expired if the “config.clean_up” is true and “config.clean_up_older_than” is the amount of seconds it is older than.
Note: This action should be used with the “bundle exec rake cloud_tempfile:clear” rake command (cronjob)
68 69 70 71 72 |
# File 'lib/cloud_tempfile/cloud_tempfile.rb', line 68 def clear with_config do self.storage.delete_expired_tempfiles end end |
.config ⇒ Object
23 24 25 26 |
# File 'lib/cloud_tempfile/cloud_tempfile.rb', line 23 def config @config ||= CloudTempfile::Config.new @config end |
.config=(data) ⇒ Object
19 20 21 |
# File 'lib/cloud_tempfile/cloud_tempfile.rb', line 19 def config=(data) @config = data end |
.configure {|@config| ... } ⇒ Object
32 33 34 35 |
# File 'lib/cloud_tempfile/cloud_tempfile.rb', line 32 def configure(&proc) @config ||= CloudTempfile::Config.new yield @config end |
.enabled? ⇒ Boolean
98 99 100 |
# File 'lib/cloud_tempfile/cloud_tempfile.rb', line 98 def enabled? config.enabled? end |
.initialize(file_name = nil, file_raw_data = nil) ⇒ Object
13 14 15 16 |
# File 'lib/cloud_tempfile/cloud_tempfile.rb', line 13 def initialize(file_name=nil, file_raw_data=nil) self.file_name = file_name self.file_raw_data = file_raw_data end |
.log(msg) ⇒ Object
94 95 96 |
# File 'lib/cloud_tempfile/cloud_tempfile.rb', line 94 def log(msg) stdout.puts msg if config.log_silently? end |
.reset_config! ⇒ Object
28 29 30 |
# File 'lib/cloud_tempfile/cloud_tempfile.rb', line 28 def reset_config! remove_instance_variable :@config if defined?(@config) end |
.stderr ⇒ Object
Log Stub methods
103 |
# File 'lib/cloud_tempfile/cloud_tempfile.rb', line 103 def stderr ; STDERR ; end |
.stdout ⇒ Object
104 |
# File 'lib/cloud_tempfile/cloud_tempfile.rb', line 104 def stdout ; STDOUT ; end |
.storage ⇒ Object
37 38 39 |
# File 'lib/cloud_tempfile/cloud_tempfile.rb', line 37 def storage @storage ||= CloudTempfile::Storage.new(self.config) end |
.warn(msg) ⇒ Object
90 91 92 |
# File 'lib/cloud_tempfile/cloud_tempfile.rb', line 90 def warn(msg) stderr.puts msg end |
.with_config(&block) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/cloud_tempfile/cloud_tempfile.rb', line 74 def with_config(&block) return unless CloudTempfile.enabled? errors = config.valid? ? "" : config.errors..join(', ') if !(config && config.valid?) if config.fail_silently? self.warn(errors) else raise CloudTempfile::Config::Invalid.new(errors) end else block.call end end |
.write(options = {}) ⇒ File
This action will responsible for persisting the Tempfile
Options
- :
file_name
: -
The file name to use for the Tempfile
- :
file_raw_data
: -
The raw file data to be persisted
- :
expiry
: -
The expiry is the number of seconds the file will available publicly
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/cloud_tempfile/cloud_tempfile.rb', line 49 def write( = {}) _file_name = ((.has_key?(:file_name))? [:file_name] : self.file_name) _file_raw_data = ((.has_key?(:file_raw_data))? [:file_raw_data] : self.file_raw_data) return false if _file_name.nil? || _file_name.blank? || _file_raw_data.nil? with_config do if !(config && config.local?) return self.storage.upload_file(_file_name, _file_raw_data, ) else return self.storage.local_file(_file_name, _file_raw_data, ) end end end |