Sha256: a4e7c2a67ac79c4021a1929e098ced7246b6f2147356a16cc3eec1af96f50e66

Contents?: true

Size: 1 KB

Versions: 2

Compression:

Stored size: 1 KB

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
      return [] if @simple_messages_models.nil? or @dont_simple_messages_models.nil?

      (@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

2 entries across 2 versions & 1 rubygems

Version Path
simple_messages-1.1.0 lib/simple_messages/action_controller.rb
simple_messages-1.0.1 lib/simple_messages/action_controller.rb