Class: Saviour::BaseUploader
- Inherits:
-
Object
- Object
- Saviour::BaseUploader
show all
- Defined in:
- lib/saviour/base_uploader.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(opts = {}) ⇒ BaseUploader
Returns a new instance of BaseUploader.
6
7
8
|
# File 'lib/saviour/base_uploader.rb', line 6
def initialize(opts = {})
@data = opts.fetch(:data, {})
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
10
11
12
13
14
15
16
|
# File 'lib/saviour/base_uploader.rb', line 10
def method_missing(name, *args, &block)
if @data.key?(name)
@data[name]
else
super
end
end
|
Class Method Details
.process(name = nil, opts = {}, type = :memory, &block) ⇒ Object
67
68
69
70
71
72
73
|
# File 'lib/saviour/base_uploader.rb', line 67
def process(name = nil, opts = {}, type = :memory, &block)
if block_given?
processors.push(method_or_block: name || block, type: type)
else
processors.push(method_or_block: name || block, type: type, opts: opts)
end
end
|
.process_with_file(name = nil, opts = {}, &block) ⇒ Object
75
76
77
|
# File 'lib/saviour/base_uploader.rb', line 75
def process_with_file(name = nil, opts = {}, &block)
process(name, opts, :file, &block)
end
|
.processors ⇒ Object
63
64
65
|
# File 'lib/saviour/base_uploader.rb', line 63
def processors
@processors ||= []
end
|
.store_dir(name = nil, &block) ⇒ Object
80
81
82
|
# File 'lib/saviour/base_uploader.rb', line 80
def store_dir(name = nil, &block)
store_dirs.push(name || block)
end
|
.store_dirs ⇒ Object
59
60
61
|
# File 'lib/saviour/base_uploader.rb', line 59
def store_dirs
@store_dirs ||= []
end
|
Instance Method Details
#_process_as_contents(contents, filename) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/saviour/base_uploader.rb', line 22
def _process_as_contents(contents, filename)
raise ConfigurationError, "Please use `store_dir` in the uploader" unless store_dir
catch(:halt_process) do
if Config.processing_enabled
contents, filename = Uploader::ProcessorsRunner.new(self).run!(contents, filename)
end
path = ::File.join(store_dir, filename)
[contents, path]
end
end
|
#_process_as_file(file, filename) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/saviour/base_uploader.rb', line 36
def _process_as_file(file, filename)
raise ConfigurationError, "Please use `store_dir` in the uploader" unless store_dir
catch(:halt_process) do
if Config.processing_enabled
file, filename = Uploader::ProcessorsRunner.new(self).run_as_file!(file, filename)
end
path = ::File.join(store_dir, filename)
[file, path]
end
end
|
#halt_process ⇒ Object
50
51
52
|
# File 'lib/saviour/base_uploader.rb', line 50
def halt_process
throw(:halt_process)
end
|
#respond_to_missing?(name) ⇒ Boolean
18
19
20
|
# File 'lib/saviour/base_uploader.rb', line 18
def respond_to_missing?(name, *)
@data.key?(name) || super
end
|
#store_dir ⇒ Object
54
55
56
|
# File 'lib/saviour/base_uploader.rb', line 54
def store_dir
@store_dir ||= Uploader::.new(self).store_dir
end
|