module Polygallery::ActsAsPolyphoto::LocalInstanceMethods

Public Instance Methods

include_polygallery_settings(settings) click to toggle source
# File lib/polygallery/acts_as_polyphoto.rb, line 66
def include_polygallery_settings(settings)
  self.polygallery_options = settings
  self.initialize_polyphoto
end
init_attachment() click to toggle source
# File lib/polygallery/acts_as_polyphoto.rb, line 140
def init_attachment
  self.class.init_attachment paperclip_settings
end
initialize_polyphoto() click to toggle source
# File lib/polygallery/acts_as_polyphoto.rb, line 71
def initialize_polyphoto
  return if self.polyphoto_initialized.present?
  self.class.init_associations(self.polygallery_settings)
  self.init_attachment
  self.polyphoto_initialized = true
end
paperclip_settings() click to toggle source
# File lib/polygallery/acts_as_polyphoto.rb, line 110
def paperclip_settings
  self.polygallery_settings[:paperclip]
end
photo_remote_url=(url_value) click to toggle source
# File lib/polygallery/acts_as_polyphoto.rb, line 158
def photo_remote_url=(url_value)
  self.photo = URI.parse process_remote_uri(url_value)
  @photo_remote_url = url_value
end
polygallery_settings() click to toggle source
# File lib/polygallery/acts_as_polyphoto.rb, line 78
def polygallery_settings
  return self.polygallery_options if self.polygallery_options.present?
  if self.gallery_title.present?
    s = if self.galleryable.present?
          galleryable.class.send(:"#{self.gallery_title}_settings")
        elsif self.galleryable_type.present?
          Kernel.const_get(self.galleryable_type)
            .send(:"#{self.gallery_title}_settings")
        end
    return s if s.present?
  elsif respond_to?(:gallery) && gallery.present?
    return gallery.polygallery_settings
  elsif self.gallery_id.present?
    g = Polygallery::Gallery.find(self.gallery_id)
    if g.present?
      self.gallery_title = g.title
      return self.polygallery_settings
    end
  end
  self.class.polygallery_settings
  # if gallery_title.present? && galleryable_type.present?
  #   galleryable_class = Kernel.const_get(galleryable_type)
  #   galleryable_class.send :"#{gallery_title}_settings"
  # elsif gallery_title.present?
  #   self.send(gallery_title.to_sym).polygallery_settings
  # elsif self.gallery.present? && gallery.polygallery_settings.present?
  #   self.gallery.polygallery_settings
  # else
  #   DEFAULT_SETTINGS
  # end
end
process_photo_to_upload() click to toggle source
# File lib/polygallery/acts_as_polyphoto.rb, line 114
def process_photo_to_upload
  # As crazy as this looks, it's necessary to assign paperclip's
  # dynamic styles through an association.  It would be great if we
  # could find a better way, though...
  #
  # This part runs the second try.
  if (new_record? || photo_updated_at_changed?) && gallery.present? &&
      photo_to_upload.present? && File.exists?(photo_to_upload)
    # puts 'Running the swaparoo!'
    File.open(photo_to_upload, 'rb') {|h| self.photo = h }
    # self.photo_to_upload = nil
  end
  # This part runs the first try.
  if self.photo.present? && self.photo_to_upload.nil?
    # if self.new_record? || self.photo_file_name_changed?
    if self.photo.staged?
      # puts "#{photo_file_name} is staged!"
      if File.exists? self.photo.staged_path
        # puts "Setting photo to upload to #{photo_file_name}"
        self.photo_to_upload = self.photo.staged_path
        # self.photo = nil
      end
    end
  end
end
process_remote_uri(uri) click to toggle source
# File lib/polygallery/acts_as_polyphoto.rb, line 153
def process_remote_uri(uri)
  require 'open-uri'
  require 'open_uri_redirections'
  open(uri, allow_redirections: :safe) {|r| r.base_uri.to_s }
end
remote_url(style=nil) click to toggle source
# File lib/polygallery/acts_as_polyphoto.rb, line 144
def remote_url(style=nil)
  host = ActionController::Base.asset_host
  host = "http://#{host}" unless host.nil? || host =~ /^http/
  path = photo.url(style)
  url = (host||'') + (path||'')
  url unless url.blank?
end
thumb_url() click to toggle source
# File lib/polygallery/acts_as_polyphoto.rb, line 151
def thumb_url; remote_url(:thumb) end