Sha256: 8643fe5e2de70fd88a1b429ca258ed8ec67e5b612853321f10c4d821882c40d1

Contents?: true

Size: 515 Bytes

Versions: 6

Compression:

Stored size: 515 Bytes

Contents

module Enjoy::Gallery::Gallerable
  extend ActiveSupport::Concern

  module ClassMethods
    def enjoy_gallerable_field(name = :enjoy_gallerable, opts = {})
      class_name = opts.delete(:class_name)
      class_name ||= "Enjoy::Gallery::Gallery"

      belongs_to name, polymorphic: true

      class_eval <<-EVAL
        before_save do
          self.#{name}_id = nil   if self.#{name}_type.nil?
          self.#{name}_type = nil if self.#{name}_id.nil?
          self
        end
      EVAL

    end
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
enjoy_cms_gallery-0.4.1 app/models/concerns/enjoy/gallery/gallerable.rb
enjoy_cms_gallery-0.4.0.2 app/models/concerns/enjoy/gallery/gallerable.rb
enjoy_cms_gallery-0.4.0.1 app/models/concerns/enjoy/gallery/gallerable.rb
enjoy_cms_gallery-0.4.0 app/models/concerns/enjoy/gallery/gallerable.rb
enjoy_cms_gallery-0.4.0.beta3 app/models/concerns/enjoy/gallery/gallerable.rb
enjoy_cms_gallery-0.4.0.beta1 app/models/concerns/enjoy/gallery/gallerable.rb