Module: FileClip::InstanceMethods
- Defined in:
- lib/fileclip.rb
Instance Method Summary collapse
-
#attachment_name ⇒ Object
TODO: can’t handle multiples, just given.
- #attachment_object ⇒ Object
- #fileclip_previously_changed? ⇒ Boolean
-
#filepicker_only? ⇒ Boolean
To be overridden in model if specific logic for not processing the image.
- #filepicker_url_not_present? ⇒ Boolean
- #process_from_filepicker ⇒ Object
- #process_with_resque! ⇒ Object
- #process_with_sidekiq! ⇒ Object
- #set_metadata ⇒ Object
- #update_from_filepicker! ⇒ Object
- #update_from_filepicker? ⇒ Boolean
Instance Method Details
#attachment_name ⇒ Object
TODO: can’t handle multiples, just given
68 69 70 |
# File 'lib/fileclip.rb', line 68 def @attachment_name ||= self.class.fileclipped end |
#attachment_object ⇒ Object
72 73 74 |
# File 'lib/fileclip.rb', line 72 def self.send() end |
#fileclip_previously_changed? ⇒ 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
138 139 140 |
# File 'lib/fileclip.rb', line 138 def filepicker_only? false end |
#filepicker_url_not_present? ⇒ 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_filepicker ⇒ Object
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(:"#{}=", URI.parse(filepicker_url)) self. self..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(:"#{}_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(:"#{}_processing", true) if FileClip.delayed? FileClip::Jobs::Sidekiq.perform_async(self.class.name, self.id) end |
#set_metadata ⇒ Object
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(:"#{}_content_type=", ["mimetype"]) # Delegate to paperclips filename cleaner filename = self..send(:cleanup_filename, ["filename"]) self.send(:"#{}_file_name=", filename) self.send(:"#{}_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
121 122 123 124 125 |
# File 'lib/fileclip.rb', line 121 def update_from_filepicker? fileclip_previously_changed? && filepicker_url.present? && !filepicker_only? end |