Module: Polygallery::ActsAsPolyphoto::LocalInstanceMethods

Defined in:
app/models/concerns/polygallery/acts_as_polyphoto.rb

Instance Method Summary collapse

Instance Method Details

#include_polygallery_settings(settings) ⇒ Object



57
58
59
60
# File 'app/models/concerns/polygallery/acts_as_polyphoto.rb', line 57

def include_polygallery_settings(settings)
  self.polygallery_options = settings
  self.initialize_polyphoto
end

#init_attachmentObject



115
116
117
# File 'app/models/concerns/polygallery/acts_as_polyphoto.rb', line 115

def init_attachment
  self.class.init_attachment paperclip_settings
end

#initialize_polyphotoObject



62
63
64
65
66
67
# File 'app/models/concerns/polygallery/acts_as_polyphoto.rb', line 62

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_settingsObject



101
102
103
# File 'app/models/concerns/polygallery/acts_as_polyphoto.rb', line 101

def paperclip_settings
  self.polygallery_settings[:paperclip]
end

#polygallery_settingsObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/models/concerns/polygallery/acts_as_polyphoto.rb', line 69

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 = Kernel.const_get(self.galleryable_type).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
  #   HasPolygallery::DEFAULTS
  # end
end

#process_photo_to_uploadObject



105
106
107
108
109
110
111
112
113
# File 'app/models/concerns/polygallery/acts_as_polyphoto.rb', line 105

def process_photo_to_upload
  if self.photo.present? && self.photo_to_upload.nil?
    if self.new_record? || self.photo_file_name_changed?
      self.photo_to_upload = self.photo.staged_path
      self.photo = nil
    end
  end
  self.photo = File.open(photo_to_upload) if photo_to_upload.present?
end

#remote_url(style = nil) ⇒ Object



119
120
121
122
123
124
125
# File 'app/models/concerns/polygallery/acts_as_polyphoto.rb', line 119

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_urlObject



126
# File 'app/models/concerns/polygallery/acts_as_polyphoto.rb', line 126

def thumb_url; remote_url(:thumb) end