Sha256: 5278368319679e11f8941f72110cd2d99d36c45f9f359ba271d76ebe3834840f

Contents?: true

Size: 912 Bytes

Versions: 2

Compression:

Stored size: 912 Bytes

Contents

module Yaps
  module ExtendPublisher
    def publish(*args)
      Yaps.configuration.enable? && super
    end
  end

  module Publisher
    extend ActiveSupport::Concern
    include Wisper::Publisher
    prepend ExtendPublisher

    module ClassMethods
      def published(opts = {})
        options = opts.clone
        include_default_actions(options)
        nil
      end

      def include_default_actions(options)
        defaults = {
          create:  Creation,
          destroy: Destruction,
          update:  Updation
        }

        modules = if options[:except]
          defaults.except(*options[:except])
        elsif options[:only]
          defaults.slice(*options[:only])
        else
          defaults
        end

        modules.each do |key, value|
          include value
        end
      end

      def available_options
        [:only, :except].freeze
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
yaps-0.1.0 lib/yaps/publisher.rb
yaps-0.0.2 lib/yaps/publisher.rb