Module: Polygallery::HasPolygallery::LocalInstanceMethods
- Defined in:
- lib/polygallery/has_polygallery.rb
Instance Method Summary collapse
- #build_first_photos ⇒ Object
- #build_galleries ⇒ Object
- #ensure_galleryable_set ⇒ Object
- #first_photo ⇒ Object
- #has_polygallery?(gallery_title = nil) ⇒ Boolean
- #polygalleries ⇒ Object
Instance Method Details
#build_first_photos ⇒ Object
125 126 127 128 |
# File 'lib/polygallery/has_polygallery.rb', line 125 def build_first_photos return unless self.class.has_polygallery? self.class.polygalleries.each {|pg| send(pg).build_first_photo } end |
#build_galleries ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/polygallery/has_polygallery.rb', line 110 def build_galleries return unless self.class.has_polygallery? self.class.polygalleries.each do |pg| gallery_association = send pg next if gallery_association.present? gallery_settings = self.send :"#{pg.to_s}_settings" if gallery_association.nil? built_gallery = send :"build_#{pg.to_s}", :polygallery_options => gallery_settings gallery_association = send :"#{pg.to_s}=", built_gallery end gallery_association.galleryable ||= self end end |
#ensure_galleryable_set ⇒ Object
144 145 146 147 148 149 150 151 152 |
# File 'lib/polygallery/has_polygallery.rb', line 144 def ensure_galleryable_set self.class.polygalleries.each do |pg| gallery_association = self.send :"#{pg}" gallery_association.galleryable ||= self gallery_association.polygallery_photos.each do |pp| pp.galleryable ||= self end end end |
#first_photo ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/polygallery/has_polygallery.rb', line 130 def first_photo return unless self.class.has_polygallery? first_p = nil self.class.polygalleries.each do |pg| gallery_settings = send :"#{pg.to_s}_settings" ptos = send(gallery_settings[:association_names][:photos]) .select{|p| p.photo.file? } next if ptos.empty? first_p = ptos.first.photo break end first_p || Photo.new.photo end |
#has_polygallery?(gallery_title = nil) ⇒ Boolean
105 106 107 108 |
# File 'lib/polygallery/has_polygallery.rb', line 105 def has_polygallery?(gallery_title=nil) return polygalleries.any? if gallery_title.nil? polygalleries.include?(gallery_title) end |
#polygalleries ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/polygallery/has_polygallery.rb', line 97 def polygalleries # TODO: use association reflections instead of direct class selection Gallery.select('polygallery_galleries.title') .where(:galleryable => self) .group('polygallery_galleries.title') .map(&:title) end |