Class: Photo
Overview
Copyright © 2009, Diaspora Inc. This file is
licensed under the Affero General Public License version 3 or later. See the COPYRIGHT file.
Class Method Summary (collapse)
Instance Method Summary (collapse)
- - (Object) as_json(opts = {})
- - (Object) ensure_user_picture
- - (Boolean) mutable?
- - (Boolean) not_processed?
- - (Object) ownership_of_status_message
- - (Object) process
- - (Boolean) processed?
- - (Object) queue_processing_job
- - (Object) thumb_hash
- - (Object) update_remote_path
- - (Object) url(name = nil)
Methods inherited from Post
#activity_streams?, #diaspora_handle, #diaspora_handle=, #receive, #subscribers, #user_refs
Methods included from Diaspora::Guid
Methods included from Diaspora::Webhooks
#receive, #subscribers, #to_diaspora_xml, #x
Methods included from ApplicationHelper
#bookmarklet, #direction_for, #get_javascript_strings_for, #hard_link, #how_long_ago, #info_text, #mine?, #object_fields, #object_path, #owner_image_link, #owner_image_tag, #person_image_link, #person_image_tag, #person_link, #post_yield_tag, #profile_photo, #rtl?, #timeago, #type_partial
Class Method Details
+ (Object) diaspora_initialize(params = {})
33 34 35 36 37 38 39 40 |
# File 'app/models/photo.rb', line 33 def self.diaspora_initialize(params = {}) photo = super(params) image_file = params.delete(:user_file) photo.random_string = ActiveSupport::SecureRandom.hex(10) photo.unprocessed_image.store! image_file photo.update_remote_path photo end |
Instance Method Details
- (Object) as_json(opts = {})
101 102 103 104 105 106 107 108 109 110 |
# File 'app/models/photo.rb', line 101 def as_json(opts={}) { :photo => { :id => self.id, :url => self.url, :thumb_small => self.url(:thumb_small), :text => self.text } } end |
- (Object) ensure_user_picture
75 76 77 78 79 80 81 |
# File 'app/models/photo.rb', line 75 def ensure_user_picture profiles = Profile.where(:image_url => url(:thumb_large)) profiles.each { |profile| profile.image_url = nil profile.save } end |
- (Boolean) mutable?
97 98 99 |
# File 'app/models/photo.rb', line 97 def mutable? true end |
- (Boolean) not_processed?
42 43 44 |
# File 'app/models/photo.rb', line 42 def not_processed? processed_image.path.nil? end |
- (Object) ownership_of_status_message
24 25 26 27 28 29 30 31 |
# File 'app/models/photo.rb', line 24 def = StatusMessage.find_by_guid(self.) if self. && self.diaspora_handle == .diaspora_handle else true end end |
- (Object) process
91 92 93 94 95 |
# File 'app/models/photo.rb', line 91 def process return false if self.processed? || (!unprocessed_image.path.nil? && unprocessed_image.path.include?('.gif')) processed_image.store!(unprocessed_image) #Ultra naive save! end |
- (Boolean) processed?
46 47 48 |
# File 'app/models/photo.rb', line 46 def processed? !processed_image.path.nil? end |
- (Object) queue_processing_job
87 88 89 |
# File 'app/models/photo.rb', line 87 def queue_processing_job Resque.enqueue(Job::ProcessPhoto, self.id) end |
- (Object) thumb_hash
83 84 85 |
# File 'app/models/photo.rb', line 83 def thumb_hash {:thumb_url => url(:thumb_medium), :id => id, :album_id => nil} end |
- (Object) update_remote_path
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/models/photo.rb', line 50 def update_remote_path unless self.unprocessed_image.url.match(/^https?:\/\//) pod_url = AppConfig[:pod_url].dup pod_url.chop! if AppConfig[:pod_url][-1,1] == '/' remote_path = "#{pod_url}#{self.unprocessed_image.url}" else remote_path = self.unprocessed_image.url end name_start = remote_path.rindex '/' self.remote_photo_path = "#{remote_path.slice(0, name_start)}/" self.remote_photo_name = remote_path.slice(name_start + 1, remote_path.length) end |
- (Object) url(name = nil)
64 65 66 67 68 69 70 71 72 73 |
# File 'app/models/photo.rb', line 64 def url(name = nil) if remote_photo_path name = name.to_s + '_' if name remote_photo_path + name.to_s + remote_photo_name elsif not_processed? unprocessed_image.url(name) else processed_image.url(name) end end |