Module: Card::Set::Abstract::Attachment

Extended by:
Card::Set
Defined in:
tmpsets/set/mod019-carrierwave/abstract/attachment.rb,
tmpsets/set/mod019-carrierwave/abstract/attachment/paths.rb,
tmpsets/set/mod019-carrierwave/abstract/attachment/storage_type.rb,
tmpsets/set/mod019-carrierwave/abstract/attachment/upload_cache.rb

Overview

Set: Abstract (Attachment)

Defined Under Namespace

Modules: Paths, StorageType, UploadCache

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from I18nScope

#mod_name, #scope

Methods included from Loader

#clean_empty_module_from_hash, #clean_empty_modules, #extended, #process_base_modules, #register_set

Methods included from Helpers

#abstract_set?, #all_set?, #num_set_parts, #shortname, #underscore

Methods included from Card::Set::AdvancedApi

#attachment, #ensure_set, #stage_method

Methods included from Format

#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name

Methods included from Inheritance

#include_set, #include_set_formats

Methods included from Basket

#abstract_basket, #add_to_basket, #basket, #unshift_basket

Methods included from Trait

#card_accessor, #card_reader, #card_writer, #require_field

Methods included from Event::Api

#event

Instance Attribute Details

#empty_ok=(value) ⇒ Object (writeonly)

Sets the attribute empty_ok

Parameters:

  • value

    the value to set the attribute empty_ok to.



10
11
12
# File 'tmpsets/set/mod019-carrierwave/abstract/attachment.rb', line 10

def empty_ok=(value)
  @empty_ok = value
end

Class Method Details

.included(host_class) ⇒ Object



12
13
14
# File 'tmpsets/set/mod019-carrierwave/abstract/attachment.rb', line 12

def self.included host_class
  host_class.extend CarrierWave::CardMount
end

.source_locationObject



7
# File 'tmpsets/set/mod019-carrierwave/abstract/attachment.rb', line 7

def self.source_location; "/Users/ethan/dev/decko/gem/card/mod/carrierwave/set/abstract/attachment.rb"; end

Instance Method Details

#assign_set_specific_attributesObject



86
87
88
89
90
# File 'tmpsets/set/mod019-carrierwave/abstract/attachment.rb', line 86

def assign_set_specific_attributes
  # reset content if we really have something to upload
  self.content = nil if set_specific[attachment_name.to_s].present?
  super
end

#attachment_before_actObject



74
75
76
# File 'tmpsets/set/mod019-carrierwave/abstract/attachment.rb', line 74

def attachment_before_act
  send "#{attachment_name}_before_act"
end

#attachment_changed?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'tmpsets/set/mod019-carrierwave/abstract/attachment.rb', line 66

def attachment_changed?
  send "#{attachment_name}_changed?"
end

#attachment_format(ext) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'tmpsets/set/mod019-carrierwave/abstract/attachment.rb', line 107

def attachment_format ext
  if ext.present? && attachment && (original_ext = attachment.extension)
    if ["file", original_ext].member? ext
      original_ext
    elsif (exts = MIME::Types[attachment.content_type])
      if exts.find { |mt| mt.extensions.member? ext }
        ext
      else
        exts[0].extensions[0]
      end
    end
  end
rescue => e
  Rails.logger.info "attachment_format issue: #{e.message}"
  nil
end

#attachment_is_changing?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'tmpsets/set/mod019-carrierwave/abstract/attachment.rb', line 70

def attachment_is_changing?
  send "#{attachment_name}_is_changing?"
end

#create_versions?(_new_file) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
# File 'tmpsets/set/mod019-carrierwave/abstract/attachment.rb', line 78

def create_versions? _new_file
  true
end

#delete_files_for_action(action) ⇒ Object



92
93
94
95
96
97
98
99
# File 'tmpsets/set/mod019-carrierwave/abstract/attachment.rb', line 92

def delete_files_for_action action
  with_selected_action_id(action.id) do
    attachment.file.delete
    attachment.versions.each_value do |version|
      version.file.delete
    end
  end
end

#empty_ok?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'tmpsets/set/mod019-carrierwave/abstract/attachment.rb', line 82

def empty_ok?
  @empty_ok
end

#file_ready_to_save?Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
# File 'tmpsets/set/mod019-carrierwave/abstract/attachment.rb', line 46

def file_ready_to_save?
  attachment.file.present? &&
    !preliminary_upload? &&
    !save_preliminary_upload? &&
    attachment_is_changing?
end

#item_names(_args = {}) ⇒ Object

needed for flexmail attachments. hacky.



53
54
55
# File 'tmpsets/set/mod019-carrierwave/abstract/attachment.rb', line 53

def item_names _args={} # needed for flexmail attachments.  hacky.
  [name]
end

#original_filenameObject



57
58
59
60
# File 'tmpsets/set/mod019-carrierwave/abstract/attachment.rb', line 57

def original_filename
  return content.split("/").last if web?
  attachment.original_filename
end

#revision(action, before_action = false) ⇒ Object



101
102
103
104
105
# File 'tmpsets/set/mod019-carrierwave/abstract/attachment.rb', line 101

def revision action, before_action=false
  return unless (result = super)
  result[:empty_ok] = true
  result
end

#unfilled?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'tmpsets/set/mod019-carrierwave/abstract/attachment.rb', line 62

def unfilled?
  !attachment.present? && !save_preliminary_upload? && !subcards? && blank_content?
end