module Polygallery::HasPolygallery::LocalInstanceMethods

Public Instance Methods

build_first_photos() click to toggle source
# File lib/polygallery/has_polygallery.rb, line 138
def build_first_photos
  return unless self.class.has_polygallery?
  # self.class.polygalleries.each{|pg|
  #   build_gallery_association pg
  #   send(pg.to_sym).build_first_photo }
  build_gallery_associations.map(&:build_first_photo)
end
ensure_galleryable_set() click to toggle source
# File lib/polygallery/has_polygallery.rb, line 155
def ensure_galleryable_set
  gallery_associations.each do |ga|
    ga.galleryable ||= self
    ga.polygallery_photos.each{|pp|
      pp.galleryable ||= self }
  end
end
first_photo(ga_name=nil) click to toggle source
# File lib/polygallery/has_polygallery.rb, line 153
def first_photo(ga_name=nil); first_polyphoto(ga_name).photo end
first_polyphoto(ga_name=nil) click to toggle source
# File lib/polygallery/has_polygallery.rb, line 146
def first_polyphoto(ga_name=nil)
  return Photo.new unless gallery_associations.any?
  ga = if ga_name.present? then send(ga_name)
       else gallery_associations.to_a.find{|pg| pg.photos.any? } end
  return Photo.new if ga.nil?
  ga.first_photo
end
galleries_built?() click to toggle source
# File lib/polygallery/has_polygallery.rb, line 165
def galleries_built?; self.galleries_built.present? end
has_polygallery?(gallery_title=nil) click to toggle source
# File lib/polygallery/has_polygallery.rb, line 82
def has_polygallery?(gallery_title=nil)
  return polygalleries.any? if gallery_title.nil?
  polygalleries.include?(gallery_title)
end
polygalleries() click to toggle source
# File lib/polygallery/has_polygallery.rb, line 69
def polygalleries
  self.class.polygalleries.each do |pg_name|
    gallery_opts = self.send(:"#{pg_name}_settings")
    gallery_classname = gallery_opts[:associations][:gallery][:class_name]
    gallery_class = Object.const_get gallery_classname
    table_name = gallery_class.table_name
    gallery_class.select("#{table_name}.title")
      .where(:galleryable => self)
      .group("#{table_name}.title")
      .map(&:title)
  end
end
prune_empty_photos() click to toggle source
# File lib/polygallery/has_polygallery.rb, line 166
def prune_empty_photos
  gallery_associations.each(&:prune_empty_photos) end
remote_urls_for_polyphotos(style=nil) click to toggle source
# File lib/polygallery/has_polygallery.rb, line 169
def remote_urls_for_polyphotos(style=nil)
  gallery_associations.map{|ga| ga.remote_urls(style) }.flatten end
thumb_url() click to toggle source
# File lib/polygallery/has_polygallery.rb, line 171
def thumb_url; first_polyphoto.thumb_url end