Module: FileClip::InstanceMethods

Defined in:
lib/fileclip.rb

Instance Method Summary collapse

Instance Method Details

#attachment_nameObject

TODO: can’t handle multiples, just given



63
64
65
# File 'lib/fileclip.rb', line 63

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

#attachment_objectObject



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

def attachment_object
  self.send(attachment_name)
end

#delay_process!Object



82
83
84
85
# File 'lib/fileclip.rb', line 82

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

#fileclip_previously_changed?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/fileclip.rb', line 120

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)


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

def filepicker_only?
  false
end

#filepicker_url_not_present?Boolean

Returns:

  • (Boolean)


115
116
117
118
# File 'lib/fileclip.rb', line 115

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

#process_from_filepickerObject



87
88
89
90
91
92
93
94
95
# File 'lib/fileclip.rb', line 87

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

#set_metadataObject



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

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



71
72
73
74
75
76
77
78
79
80
# File 'lib/fileclip.rb', line 71

def update_from_filepicker!
  if update_from_filepicker?
    if FileClip.resque_enabled?
      # TODO: self.class.name is webrick ???
      delay_process!
    else
      process_from_filepicker
    end
  end
end

#update_from_filepicker?Boolean

Returns:

  • (Boolean)


109
110
111
112
113
# File 'lib/fileclip.rb', line 109

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