Class: FileColumn::BaseUploadedFile

Inherits:
Object
  • Object
show all
Defined in:
lib/file_column.rb

Overview

:nodoc:

Direct Known Subclasses

NoUploadedFile, RealUploadedFile

Instance Method Summary collapse

Constructor Details

#initialize(instance, attr) ⇒ BaseUploadedFile

Returns a new instance of BaseUploadedFile.



51
52
53
54
# File 'lib/file_column.rb', line 51

def initialize(instance,attr)
  @instance, @attr = instance, attr
  @options_method = "#{attr}_options".to_sym
end

Instance Method Details

#absolute_dirObject



105
106
107
# File 'lib/file_column.rb', line 105

def absolute_dir
  if absolute_path then File.dirname(absolute_path) else nil end
end

#after_destroyObject



118
119
# File 'lib/file_column.rb', line 118

def after_destroy
end

#after_saveObject



113
114
115
116
# File 'lib/file_column.rb', line 113

def after_save
  @on_save.each { |blk| blk.call } if @on_save
  self
end

#assign(file) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/file_column.rb', line 60

def assign(file)
  if file.is_a? File
    # this did not come in via a CGI request. However,
    # assigning files directly may be useful, so we
    # make just this file object similar enough to an uploaded
    # file that we can handle it.
    file.extend FileColumn::FileCompat
  end

  if file.nil?
    delete
  else
    if file.size == 0
      # user did not submit a file, so we
      # can simply ignore this
      self
    else
      if file.is_a?(String)
        # if file is a non-empty string it is most probably
        # the filename and the user forgot to set the encoding
        # to multipart/form-data. Since we would raise an exception
        # because of the missing "original_filename" method anyways,
        # we raise a more meaningful exception rightaway.
        raise TypeError.new("Do not know how to handle a string with value '#{file}' that was passed to a file_column. Check if the form's encoding has been set to 'multipart/form-data'.")
      end
      upload(file)
    end
  end
end

#just_uploaded?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/file_column.rb', line 90

def just_uploaded?
  @just_uploaded
end

#on_save(&blk) ⇒ Object



94
95
96
97
# File 'lib/file_column.rb', line 94

def on_save(&blk)
  @on_save ||= []
  @on_save << Proc.new
end

#optionsObject



121
122
123
# File 'lib/file_column.rb', line 121

def options
  @instance.send(@options_method)
end

#relative_dirObject



109
110
111
# File 'lib/file_column.rb', line 109

def relative_dir
  if relative_path then File.dirname(relative_path) else nil end
end

#storeObject



56
57
58
# File 'lib/file_column.rb', line 56

def store
  nil
end

#temp_pathObject

the following methods are overriden by sub-classes if needed



101
102
103
# File 'lib/file_column.rb', line 101

def temp_path
  nil
end