Module: FileClip::InstanceMethods

Defined in:
lib/fileclip.rb

Instance Method Summary collapse

Instance Method Details

#attachment_nameObject

TODO: can’t handle multiples, just given



68
69
70
# File 'lib/fileclip.rb', line 68

def attachment_name
  @attachment_name ||= self.class.fileclipped
end

#attachment_objectObject



72
73
74
# File 'lib/fileclip.rb', line 72

def attachment_object
  self.send(attachment_name)
end

#fileclip_previously_changed?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/fileclip.rb', line 132

def fileclip_previously_changed?
  !(previous_changes.keys.map(&:to_sym) & FileClip.change_keys).empty?
end

#filepicker_only?Boolean

To be overridden in model if specific logic for not processing the image

Returns:

  • (Boolean)


138
139
140
# File 'lib/fileclip.rb', line 138

def filepicker_only?
  false
end

#filepicker_url_not_present?Boolean

Returns:

  • (Boolean)


127
128
129
130
# File 'lib/fileclip.rb', line 127

def filepicker_url_not_present?
  return true unless self.class.column_names.include? "filepicker_url"
  !filepicker_url.present?
end

#process_from_filepickerObject



99
100
101
102
103
104
105
106
107
# File 'lib/fileclip.rb', line 99

def process_from_filepicker
  self.class.skip_callback :commit, :after, :update_from_filepicker!
  self.send(:"#{attachment_name}=", URI.parse(filepicker_url))
  self.
  self.attachment_object.save_with_prepare_enqueueing if FileClip.delayed?
  self.save
  self.enqueue_delayed_processing if FileClip.delayed?
  self.class.set_callback :commit, :after, :update_from_filepicker!
end

#process_with_resque!Object



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

def process_with_resque!
  update_column(:"#{attachment_name}_processing", true) if FileClip.delayed?
  ::Resque.enqueue(FileClip::Jobs::Resque, self.class.name, self.id)
end

#process_with_sidekiq!Object



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

def process_with_sidekiq!
  update_column(:"#{attachment_name}_processing", true) if FileClip.delayed?
  FileClip::Jobs::Sidekiq.perform_async(self.class.name, self.id)
end

#set_metadataObject



109
110
111
112
113
114
115
116
117
118
119
# File 'lib/fileclip.rb', line 109

def 
   = JSON.parse(::RestClient.get filepicker_url + "/metadata")

  self.send(:"#{attachment_name}_content_type=",  ["mimetype"])

  # Delegate to paperclips filename cleaner
  filename = self.attachment_object.send(:cleanup_filename, ["filename"])
  self.send(:"#{attachment_name}_file_name=",     filename)

  self.send(:"#{attachment_name}_file_size=",     ["size"])
end

#update_from_filepicker!Object



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/fileclip.rb', line 76

def update_from_filepicker!
  if update_from_filepicker?
    if FileClip.resque_enabled?
      # TODO: self.class.name is webrick ???
      process_with_resque!
    elsif FileClip.sidekiq_enabled?
      process_with_sidekiq!
    else
      process_from_filepicker
    end
  end
end

#update_from_filepicker?Boolean

Returns:

  • (Boolean)


121
122
123
124
125
# File 'lib/fileclip.rb', line 121

def update_from_filepicker?
  fileclip_previously_changed? &&
  filepicker_url.present? &&
  !filepicker_only?
end