Module: FileColumn

Included in:
ActiveRecord::Base
Defined in:
lib/file_column.rb,
lib/file_compat.rb,
lib/validations.rb,
lib/magick_file_column.rb

Overview

:nodoc:

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



6
7
8
9
# File 'lib/file_column.rb', line 6

def self.append_features(base)
  super
  base.extend(ClassMethods)
end

.create_state(instance, attr) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/file_column.rb', line 11

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



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/file_column.rb', line 20

def self.init_options(defaults, model, attr)
  options = defaults.dup
  options[:store_dir] ||= File.join(options[:root_path], model, attr)
  unless options[:store_dir].is_a?(Symbol)
    options[:tmp_base_dir] ||= File.join(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