Sha256: 6fdc7096ef09c9fa2f147a227ebef005269beca6005d937284c356fa89bfdb27

Contents?: true

Size: 942 Bytes

Versions: 1

Compression:

Stored size: 942 Bytes

Contents

module SimpleMessages
  module ActionController
    extend ActiveSupport::Concern

    included do
      helper_method :simple_messages_for_model, :dont_simple_messages_for_model, :simple_messages_models

      before_action :simple_messages_initialize, :simple_messages_for_current_controller
    end

    def simple_messages_for_model(*model_name)
      @simple_messages_models.concat model_name
    end

    def dont_simple_messages_for_model(*model_name)
      @dont_simple_messages_models.concat model_name
    end

    def simple_messages_models
      (@simple_messages_models.collect(&:to_sym) - @dont_simple_messages_models.collect(&:to_sym)).compact.uniq
    end

    private

    def simple_messages_initialize
      @dont_simple_messages_models ||= []
      @simple_messages_models ||= []
    end

    def simple_messages_for_current_controller
      @simple_messages_models << controller_name.singularize.to_sym
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simple_messages-1.0.0 lib/simple_messages/action_controller.rb