Module: FileColumn
- Included in:
- ActiveRecord::Base
- Defined in:
- lib/file_column.rb,
lib/file_compat.rb,
lib/magick_file_column.rb,
lib/file_column/validations.rb
Overview
Defined Under Namespace
Modules: ClassMethods, FileCompat, MagickExtension, Validations
Classes: BaseUploadedFile, NoUploadedFile, PermanentUploadedFile, RealUploadedFile, TempUploadedFile
Class Method Summary
collapse
Class Method Details
.append_features(base) ⇒ Object
8
9
10
11
|
# File 'lib/file_column.rb', line 8
def self.append_features(base)
super
base.extend(ClassMethods)
end
|
.config_store(type, build_opts = {}) ⇒ Object
28
29
30
31
|
# File 'lib/file_column.rb', line 28
def self.config_store(type, build_opts={})
@build_opts = build_opts
@store_builder = Storage::Builder.new(type)
end
|
.create_state(instance, attr) ⇒ Object
13
14
15
16
17
18
19
20
|
# File 'lib/file_column.rb', line 13
def self.create_state(instance,attr)
filename = instance[attr]
if filename.nil? or filename.empty?
NoUploadedFile.new(instance,attr)
else
PermanentUploadedFile.new(instance,attr)
end
end
|
.init_options(defaults, model, attr) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/file_column.rb', line 33
def self.init_options(defaults, model, attr)
options = defaults.dup
options[:store_dir] ||= File.join(model, attr)
unless options[:store_dir].is_a?(Symbol)
options[:tmp_base_dir] ||= File.join(options[:root_path], options[:store_dir], "tmp")
end
options[:base_url] ||= options[:web_root] + File.join(model, attr)
[:store_dir, :tmp_base_dir].each do |dir_sym|
if options[dir_sym].is_a?(String) and !File.exists?(options[dir_sym])
FileUtils.mkpath(options[dir_sym])
end
end
options
end
|
.store(path_prefix, extra_opts = {}) ⇒ Object
22
23
24
25
26
|
# File 'lib/file_column.rb', line 22
def self.store(path_prefix, ={})
builder = @store_builder || Storage::Builder.new(:filesystem)
@build_opts ||= {}
builder.build(path_prefix, @build_opts.merge())
end
|