Class: WflFileBase::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/wfl_file_base/base.rb
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(column, model) ⇒ Base
Returns a new instance of Base.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/wfl_file_base/base.rb', line 6
def initialize column, model
self.column = column
self.model = model
self.store = false
if model.read_attribute(column).is_a? File
self.file = model.read_attribute(column)
elsif model.read_attribute(column).is_a? Tempfile
self.file = model.read_attribute(column)
elsif model.read_attribute(column).is_a?(Hash) && model.read_attribute(column)[:tempfile].is_a?(Tempfile)
self.file = model.read_attribute(column)[:tempfile]
elsif self.filename.is_a?(String) && !self.filename.empty? && File.exist?(self.path)
self.file = File.open(self.path)
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
50
51
52
53
54
|
# File 'lib/wfl_file_base/base.rb', line 50
def method_missing(method, *args)
if file
file.methods.include?(method) ? file.send(method, *args) : super
end
end
|
Class Attribute Details
.wfl_pre_process_methods ⇒ Object
Returns the value of attribute wfl_pre_process_methods.
65
66
67
|
# File 'lib/wfl_file_base/base.rb', line 65
def wfl_pre_process_methods
@wfl_pre_process_methods
end
|
.wfl_process_methods ⇒ Object
Returns the value of attribute wfl_process_methods.
65
66
67
|
# File 'lib/wfl_file_base/base.rb', line 65
def wfl_process_methods
@wfl_process_methods
end
|
Instance Attribute Details
#column ⇒ Object
Returns the value of attribute column.
4
5
6
|
# File 'lib/wfl_file_base/base.rb', line 4
def column
@column
end
|
#file ⇒ Object
Returns the value of attribute file.
4
5
6
|
# File 'lib/wfl_file_base/base.rb', line 4
def file
@file
end
|
#model ⇒ Object
Returns the value of attribute model.
4
5
6
|
# File 'lib/wfl_file_base/base.rb', line 4
def model
@model
end
|
#store ⇒ Object
Returns the value of attribute store.
4
5
6
|
# File 'lib/wfl_file_base/base.rb', line 4
def store
@store
end
|
Class Method Details
.pre_process(method_name) ⇒ Object
72
73
74
75
|
# File 'lib/wfl_file_base/base.rb', line 72
def pre_process method_name
@wfl_pre_process_methods ||= []
@wfl_pre_process_methods.push method_name
end
|
.process(method_name) ⇒ Object
67
68
69
70
|
# File 'lib/wfl_file_base/base.rb', line 67
def process method_name
@wfl_process_methods ||= []
@wfl_process_methods.push method_name
end
|
Instance Method Details
#abs_store_dir ⇒ Object
37
38
39
|
# File 'lib/wfl_file_base/base.rb', line 37
def abs_store_dir
"#{WflFileBase.config.root}#{self.store_dir}"
end
|
#filename ⇒ Object
25
26
27
|
# File 'lib/wfl_file_base/base.rb', line 25
def filename
'original'
end
|
#is_new? ⇒ Boolean
60
61
62
|
# File 'lib/wfl_file_base/base.rb', line 60
def is_new?
model.read_attribute(column).is_a?(File) || model.read_attribute(column).is_a?(Tempfile) || (model.read_attribute(column).is_a?(Hash) && model.read_attribute(column)[:tempfile].is_a?(Tempfile))
end
|
#path ⇒ Object
29
30
31
|
# File 'lib/wfl_file_base/base.rb', line 29
def path
"#{WflFileBase.config.root}#{self.url}"
end
|
#read ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/wfl_file_base/base.rb', line 42
def read
if file && !File.directory?(file)
file.send(:read)
else
nil
end
end
|
#respond_to?(method) ⇒ Boolean
56
57
58
|
# File 'lib/wfl_file_base/base.rb', line 56
def respond_to? method
file.methods.include?(method) || super
end
|
#store_dir ⇒ Object
21
22
23
|
# File 'lib/wfl_file_base/base.rb', line 21
def store_dir
model.id
end
|
#url ⇒ Object
33
34
35
|
# File 'lib/wfl_file_base/base.rb', line 33
def url
"#{self.store_dir}/#{self.filename}"
end
|