Sha256: aeb7f41b00e929330db9a3026d4dffeb4abb70922f066aa27a9aaef6d7ff92a8

Contents?: true

Size: 959 Bytes

Versions: 6

Compression:

Stored size: 959 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
        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

6 entries across 6 versions & 1 rubygems

Version Path
push_type_core-0.8.2 app/models/concerns/push_type/unexposable.rb
push_type_core-0.8.1 app/models/concerns/push_type/unexposable.rb
push_type_core-0.8.0 app/models/concerns/push_type/unexposable.rb
push_type_core-0.8.0.beta.3 app/models/concerns/push_type/unexposable.rb
push_type_core-0.8.0.beta.2 app/models/concerns/push_type/unexposable.rb
push_type_core-0.8.0.beta.1 app/models/concerns/push_type/unexposable.rb