Module: FileColumnHelpers

Defined in:
lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/file_column/lib/file_column_helpers.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.file_column_fields(klass) ⇒ Object



3
4
5
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/file_column/lib/file_column_helpers.rb', line 3

def file_column_fields(klass)
  klass.instance_methods.grep(/_just_uploaded\?$/).collect{|m| m[0..-16].to_sym }
end

.generate_delete_helpers(klass) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/file_column/lib/file_column_helpers.rb', line 7

def generate_delete_helpers(klass)
  file_column_fields(klass).each { |field|
    klass.send :class_eval, <<-EOF, __FILE__, __LINE__ + 1  unless klass.methods.include?("#{field}_with_delete=")
      attr_reader :delete_#{field}
      
      def delete_#{field}=(value)
        value = (value=="true") if String===value
        return unless value
        
        # passing nil to the file column causes the file to be deleted.  Don't delete if we just uploaded a file!
        self.#{field} = nil unless self.#{field}_just_uploaded?
      end
    EOF
  }
end

.klass_has_file_column_fields?(klass) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/file_column/lib/file_column_helpers.rb', line 23

def klass_has_file_column_fields?(klass)
  true unless file_column_fields(klass).empty?
end

Instance Method Details

#field_has_image_version?(field, version = "thumb") ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
44
45
46
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/file_column/lib/file_column_helpers.rb', line 36

def field_has_image_version?(field, version="thumb")
  begin
    # the only way to get to the options of a particular field is to use the instance method
    options = options_for_file_column_field(field)
    versions = options[:magick][:versions]
    raise unless versions.stringify_keys[version]
    true
  rescue
    false
  end
end

#file_column_fieldsObject



28
29
30
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/file_column/lib/file_column_helpers.rb', line 28

def file_column_fields
  @file_column_fields||=FileColumnHelpers.file_column_fields(self)
end

#generate_delete_helpersObject



48
49
50
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/file_column/lib/file_column_helpers.rb', line 48

def generate_delete_helpers
  FileColumnHelpers.generate_delete_helpers(self)
end

#options_for_file_column_field(field) ⇒ Object



32
33
34
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/file_column/lib/file_column_helpers.rb', line 32

def options_for_file_column_field(field)
  self.allocate.send("#{field}_options")
end