Sha256: 2ea429f28ea9aaf204dbfd57baa7e576e2b59308ee55c535b0ab91b81ed56707

Contents?: true

Size: 1016 Bytes

Versions: 18

Compression:

Stored size: 1016 Bytes

Contents

module PushType
  module Unexposable
    extend ActiveSupport::Concern

    included do
      scope :exposed, -> {
        unexposed_classes.present? ? where.not(type: unexposed_classes) : all
      }
    end

    def exposed?
      self.class.exposed?
    end

    module ClassMethods

      def descendants(opts = {})
        if opts.has_key? :exposed
          super().select { |d| !opts[:exposed] == PushType.send(unexposure_method).include?(d.name.underscore) }
        else
          super()
        end
      end

      def unexposed_classes
        _ct.base_class.descendants(exposed: false)
      end

      def unexposure_method
        case _ct.base_class.name.demodulize
          when 'Node'     then :unexposed_nodes
          when 'Taxonomy' then :unexposed_taxonomies
        end
      end

      def unexpose!
        PushType.config.send(unexposure_method).push(self.name.underscore.to_sym).uniq!
      end

      def exposed?
        !unexposed_classes.include?(self)
      end

    end

  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
push_type_core-0.7.0 app/models/concerns/push_type/unexposable.rb
push_type_core-0.7.0.beta.1 app/models/concerns/push_type/unexposable.rb
push_type_core-0.6.0 app/models/concerns/push_type/unexposable.rb
push_type_core-0.6.0.beta.4 app/models/concerns/push_type/unexposable.rb
push_type_core-0.6.0.beta.3 app/models/concerns/push_type/unexposable.rb
push_type_core-0.6.0.beta.2 app/models/concerns/push_type/unexposable.rb
push_type_core-0.6.0.beta.1 app/models/concerns/push_type/unexposable.rb
push_type_core-0.5.3 app/models/concerns/push_type/unexposable.rb
push_type_core-0.5.2 app/models/concerns/push_type/unexposable.rb
push_type_core-0.5.1 app/models/concerns/push_type/unexposable.rb
push_type_core-0.5.0 app/models/concerns/push_type/unexposable.rb
push_type_core-0.5.0.alpha.5 app/models/concerns/push_type/unexposable.rb
push_type_core-0.5.0.alpha.4 app/models/concerns/push_type/unexposable.rb
push_type_core-0.5.0.alpha.3 app/models/concerns/push_type/unexposable.rb
push_type_core-0.5.0.alpha.2 app/models/concerns/push_type/unexposable.rb
push_type_core-0.5.0.alpha.1 app/models/concerns/push_type/unexposable.rb
push_type_core-0.4.0 app/models/concerns/push_type/unexposable.rb
push_type_core-0.4.0.beta.3 app/models/concerns/push_type/unexposable.rb