Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 52 lines (41 sloc) 1.034 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
require 'active_record'

module Newscloud
  module Acts
    module Galleryable

      def self.included(base)
        base.extend ClassMethods
      end

      module ClassMethods
        def acts_as_galleryable
          has_many :gallery_items, :as => :galleryable, :dependent => :nullify
          has_many :galleries, :through => :gallery_items

          accepts_nested_attributes_for :gallery_items,
            :reject_if => proc { |attrs| attrs.all? { |k,v| v.blank? } }

          include Newscloud::Acts::Galleryable::InstanceMethods
        end
      end

      module InstanceMethods
        def galleryable?
          true
        end

=begin
# TODO:: Get this working
# Use a better base value
def thumb_url
nil
end

# Use a better base value
def full_url
nil
end
=end

        def video_item?
          self.class.name == Video.name
        end

        def image_item?
          self.class.name == Image.name
        end

      end
    end
  end
end
Something went wrong with that request. Please try again.