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

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

Defined Under Namespace

Modules: Paths, StorageType, UploadCache

Constant Summary

Constants included from Helpers

Helpers::SET_PATTERN_TEST_REGEXP

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Card::Set

reset_modules

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

#method_missing, #num_set_parts, #pattern_code, #respond_to_missing?, #set_name_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.



6
7
8
# File 'tmpsets/set/mod015-carrierwave/abstract/attachment.rb', line 6

def empty_ok=(value)
  @empty_ok = value
end

Class Method Details

.included(host_class) ⇒ Object



8
9
10
# File 'tmpsets/set/mod015-carrierwave/abstract/attachment.rb', line 8

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

Instance Method Details

#assign_set_specific_attributesObject



77
78
79
80
81
82
83
# File 'tmpsets/set/mod015-carrierwave/abstract/attachment.rb', line 77

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

#attachment_changed?Boolean

Returns:

  • (Boolean)


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

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

#attachment_format(ext) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'tmpsets/set/mod015-carrierwave/abstract/attachment.rb', line 99

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

#create_versions?(new_file) ⇒ Boolean

Returns:

  • (Boolean)


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

def create_versions? new_file
  true
end

#delete_files_for_action(action) ⇒ Object



85
86
87
88
89
90
91
92
# File 'tmpsets/set/mod015-carrierwave/abstract/attachment.rb', line 85

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)


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

def empty_ok?
  @empty_ok
end

#file_ready_to_save?Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
# File 'tmpsets/set/mod015-carrierwave/abstract/attachment.rb', line 44

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

#item_names(_args = {}) ⇒ Object

needed for flexmail attachments. hacky.



51
52
53
# File 'tmpsets/set/mod015-carrierwave/abstract/attachment.rb', line 51

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

#original_filenameObject



55
56
57
58
# File 'tmpsets/set/mod015-carrierwave/abstract/attachment.rb', line 55

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

#rollback_to(action) ⇒ Object

create filesystem links to files from prior action



95
96
97
# File 'tmpsets/set/mod015-carrierwave/abstract/attachment.rb', line 95

def rollback_to action
  update_attributes! revision(action).merge(empty_ok: true)
end

#unfilled?Boolean

Returns:

  • (Boolean)


60
61
62
63
# File 'tmpsets/set/mod015-carrierwave/abstract/attachment.rb', line 60

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