<commit_before>module ActiveScaffold::DataStructures
  class ActionLink
    NO_OPTIONS = {}.freeze

    # provides a quick way to set any property of the object from a hash
    def initialize(action, options = {})
      # set defaults
      @action = action
      @label = action
      @confirm = false
      @type = :collection
      @method = :get
      @crud_type =
        case action&.to_sym
        when :destroy then :delete
        when :create, :new then :create
        when :update, :edit then :update
        else :read
        end
      @column = nil
      @image = nil
      @controller = nil
      @parameters = nil
      @dynamic_parameters = nil
      @html_options = nil
      @weight = 0
      self.inline = true

      # apply quick properties
      options.each_pair do |k, v|
        setter = "#{k}="
        send(setter, v) if respond_to? setter
      end
      self.toggle = self.action&.to_sym == :index && (parameters.present? || dynamic_parameters) unless options.include? :toggle
    end

    def initialize_copy(action_link)
      self.parameters = parameters.clone if action_link.instance_variable_get(:@parameters)
      self.html_options = html_options.clone if action_link.instance_variable_get(:@html_options)
    end

    # the weight for this link in the action links collection, it will be used to sort the collection
    attr_accessor :weight

    # the action-path for this link. what page to request? this is required!
    attr_accessor :action

    # the controller for this action link. if nil, the current controller should be assumed.
    attr_writer :controller

    def controller
      @controller = @controller.call if @controller.is_a?(Proc)
      @controller
    end

    def static_controller?
      !(@controller.is_a?(Proc) || (@controller == :polymorph))
    end

    # a hash of request parameters
    attr_writer :parameters
    def parameters
      return @parameters || NO_OPTIONS if frozen?
      @parameters ||= NO_OPTIONS.dup
    end

    # if active class is added to link when current request matches link
    # enabled automatically for links to index with parameters or dynamic parameters
    # disable when is not needed so current request match check is skipped
    attr_accessor :toggle

    # a block for dynamic_parameters
    attr_accessor :dynamic_parameters

    # the RESTful method
    attr_accessor :method

    # what string to use to represent this action
    attr_writer :label
    def label
      @label.is_a?(Symbol) ? ActiveScaffold::Registry.cache(:translations, @label) { as_(@label) } : @label
    end

    # image to use {:name => 'arrow.png', :size => '16x16'}
    attr_accessor :image

    # if the action requires confirmation
    def confirm=(value)
      @dhtml_confirm = nil if value
      @confirm = value
    end

    def confirm(label = '')
      return @confirm if @confirm.is_a?(String)
      ActiveScaffold::Registry.cache(:translations, @confirm) { as_(@confirm) } % {label: label}
    end

    def confirm?
      @confirm.present?<commit_msg>fix confirm method when confirm is not set<commit_after>module ActiveScaffold::DataStructures
  class ActionLink
    NO_OPTIONS = {}.freeze

    # provides a quick way to set any property of the object from a hash
    def initialize(action, options = {})
      # set defaults
      @action = action
      @label = action
      @confirm = false
      @type = :collection
      @method = :get
      @crud_type =
        case action&.to_sym
        when :destroy then :delete
        when :create, :new then :create
        when :update, :edit then :update
        else :read
        end
      @column = nil
      @image = nil
      @controller = nil
      @parameters = nil
      @dynamic_parameters = nil
      @html_options = nil
      @weight = 0
      self.inline = true

      # apply quick properties
      options.each_pair do |k, v|
        setter = "#{k}="
        send(setter, v) if respond_to? setter
      end
      self.toggle = self.action&.to_sym == :index && (parameters.present? || dynamic_parameters) unless options.include? :toggle
    end

    def initialize_copy(action_link)
      self.parameters = parameters.clone if action_link.instance_variable_get(:@parameters)
      self.html_options = html_options.clone if action_link.instance_variable_get(:@html_options)
    end

    # the weight for this link in the action links collection, it will be used to sort the collection
    attr_accessor :weight

    # the action-path for this link. what page to request? this is required!
    attr_accessor :action

    # the controller for this action link. if nil, the current controller should be assumed.
    attr_writer :controller

    def controller
      @controller = @controller.call if @controller.is_a?(Proc)
      @controller
    end

    def static_controller?
      !(@controller.is_a?(Proc) || (@controller == :polymorph))
    end

    # a hash of request parameters
    attr_writer :parameters
    def parameters
      return @parameters || NO_OPTIONS if frozen?
      @parameters ||= NO_OPTIONS.dup
    end

    # if active class is added to link when current request matches link
    # enabled automatically for links to index with parameters or dynamic parameters
    # disable when is not needed so current request match check is skipped
    attr_accessor :toggle

    # a block for dynamic_parameters
    attr_accessor :dynamic_parameters

    # the RESTful method
    attr_accessor :method

    # what string to use to represent this action
    attr_writer :label
    def label
      @label.is_a?(Symbol) ? ActiveScaffold::Registry.cache(:translations, @label) { as_(@label) } : @label
    end

    # image to use {:name => 'arrow.png', :size => '16x16'}
    attr_accessor :image

    # if the action requires confirmation
    def confirm=(value)
      @dhtml_confirm = nil if value
      @confirm = value
    end

    def confirm(label = '')
      return @confirm if !confirm? || @confirm.is_a?(String)
      ActiveScaffold::Registry.cache(:translations, @confirm) { as_(@confirm) } % {label: label}
    end

    def confirm?
      @confirm.present?
{'fraction_non_alphanumeric': 0.08292523669604962, 'fraction_numerical': 0.001632386549134835, 'mean_word_length': 2.7542892156862746, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '129421', 'n_tokens_mistral': 1720, 'n_tokens_neox': 1683, 'n_words': 589}