<commit_before># toolbar items come from actions

module WulinMaster
  module GridActions
    extend ActiveSupport::Concern
    
    included do
      class_eval do
        ORIGINAL_ACTIONS = %w(add delete edit filter)

        class << self
          attr_reader :actions_pool
        end
      end
    end
    
    # --------------------- Class Methods ----------------------------
    module ClassMethods
      def initialize_actions
        @actions_pool ||= []
      end

      # action DSL, add an action to the actions_pool
      def action(a_name, options={})
        new_action = {name: a_name}.merge(options)
        @actions_pool.unshift new_action
      end

      def add_actions(*args)
        args.each do |arg|
          self.action(arg)
        end
      end

      def remove_actions(*args)
        args.each do |arg|
          @actions_pool.delete_if { |action| action[:name] == arg.to_s}
        end
      end

      def load_default_actions(options={})
        ORIGINAL_ACTIONS.each do |oa|
          self.action(oa, options)
        end
      end

      # interface open to other plugins
      def add_default_action(action)
        ORIGINAL_ACTIONS << action
      end
    end

    # ----------------------- Instance Methods ------------------------------

    # the actions of a grid instance, filtered by screen param from class's actions_pool 
    def actions
      self.class.actions_pool.select {|action| valid_actions?(action, self.params["screen"]) }  
    end

    # the actions on the toolbar
    def toolbar_actions
      actions.reject {|action| action[:toolbar_item] == false}
    end

    # the actions on the grid header (not on the toolbar)
    def header_actions
      actions.select {|action| action[:toolbar_item] == false}
    end

    def action_names
      actions.map {|a| a[:name].to_s}
    end

    private

    def valid_actions?(action, screen_name)
      (action[:only].blank? and action[:except].blank?) ||
      (action[:only].present? and screen_name and action[:only].include?(screen_name.intern)) ||
      (action[:except].present? and screen_name and action[:except].exclude?(screen_name.intern))
    end

  end
end<commit_msg>MISC - rename method name, valid_actions? -> valid_action?<commit_after># toolbar items come from actions

module WulinMaster
  module GridActions
    extend ActiveSupport::Concern
    
    included do
      class_eval do
        ORIGINAL_ACTIONS = %w(add delete edit filter)

        class << self
          attr_reader :actions_pool
        end
      end
    end
    
    # --------------------- Class Methods ----------------------------
    module ClassMethods
      def initialize_actions
        @actions_pool ||= []
      end

      # action DSL, add an action to the actions_pool
      def action(a_name, options={})
        new_action = {name: a_name}.merge(options)
        @actions_pool.unshift new_action
      end

      def add_actions(*args)
        args.each do |arg|
          self.action(arg)
        end
      end

      def remove_actions(*args)
        args.each do |arg|
          @actions_pool.delete_if { |action| action[:name] == arg.to_s}
        end
      end

      def load_default_actions(options={})
        ORIGINAL_ACTIONS.each do |oa|
          self.action(oa, options)
        end
      end

      # interface open to other plugins
      def add_default_action(action)
        ORIGINAL_ACTIONS << action
      end
    end

    # ----------------------- Instance Methods ------------------------------

    # the actions of a grid instance, filtered by screen param from class's actions_pool 
    def actions
      self.class.actions_pool.select {|action| valid_action?(action, self.params["screen"]) }  
    end

    # the actions on the toolbar
    def toolbar_actions
      actions.reject {|action| action[:toolbar_item] == false}
    end

    # the actions on the grid header (not on the toolbar)
    def header_actions
      actions.select {|action| action[:toolbar_item] == false}
    end

    def action_names
      actions.map {|a| a[:name].to_s}
    end

    private

    def valid_action?(action, screen_name)
      (action[:only].blank? and action[:except].blank?) ||
      (action[:only].present? and screen_name and action[:only].include?(screen_name.intern)) ||
      (action[:except].present? and screen_name and action[:except].exclude?(screen_name.intern))
    end

  end
end
{'fraction_non_alphanumeric': 0.1310954865048764, 'fraction_numerical': 0.0, 'mean_word_length': 2.054016620498615, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '958917', 'n_tokens_mistral': 1260, 'n_tokens_neox': 1217, 'n_words': 342}