<commit_before>module RoleAuthorization
  module Exts
    module View
       def self.included(base)
         base.class_eval do
           alias_method :link_to_open, :link_to
           alias_method :link_to, :link_to_secured

           alias_method :button_to_open, :button_to
           alias_method :button_to, :button_to_secured

           alias_method :form_for_open, :form_for
           alias_method :form_for, :form_for_secured
         end
       end

      def form_for_secured(record_or_name_or_array, *args, &proc)
        options = args.last.is_a?(Hash) ? args.last : {}

        url = url_for(options[:url] || record_or_name_or_array)

        method = (options[:html] && options[:html].has_key?(:method)) ? options[:html][:method] : :post

        if authorized?(url, method)
          return form_for_open(record_or_name_or_array, *args, &proc)
        else
          return ""
        end
      end

      def link_to_secured(name, options = {}, html_options = nil)
        url = url_for(options)

        method = (html_options && html_options.has_key?(:method)) ? html_options[:method] : :get

        if authorized?(url, method)
          return link_to_open(name, url, html_options)
        else
          return ""
        end
      end

      def button_to_secured(name, options = {}, html_options = nil)
        url = url_for(options)

        method = (html_options && html_options.has_key?(:method)) ? html_options[:method] : :post

        if authorized?(url, method)
          return button_to_open(name, url, html_options)
        else
          return ""
        end<commit_msg>fix bug in view<commit_after>module RoleAuthorization
  module Exts
    module View
       def self.included(base)
         base.class_eval do
           alias_method :link_to_open, :link_to
           alias_method :link_to, :link_to_secured

           alias_method :button_to_open, :button_to
           alias_method :button_to, :button_to_secured

           alias_method :form_for_open, :form_for
           alias_method :form_for, :form_for_secured
         end
       end

      def form_for_secured(record_or_name_or_array, *args, &proc)
        options = args.last.is_a?(Hash) ? args.last : {}

        url = url_for(options[:url] || record_or_name_or_array)

        method = (options[:html] && options[:html].has_key?(:method)) ? options[:html][:method] : :post

        if authorized?(url, method)
          return form_for_open(record_or_name_or_array, *args, &proc)
        else
          return ""
        end
      end

      def link_to_secured(name, options = {}, html_options = {})
        url = url_for(options)

        method = (html_options && html_options.has_key?(:method)) ? html_options[:method] : :get

        if authorized?(url, method)
          return link_to_open(name, url, html_options)
        else
          return ""
        end
      end

      def button_to_secured(name, options = {}, html_options = {})
        url = url_for(options)

        method = (html_options && html_options.has_key?(:method)) ? html_options[:method] : :post

        if authorized?(url, method)
          return button_to_open(name, url, html_options)
        else
          return ""
        end
{'fraction_non_alphanumeric': 0.1011166253101737, 'fraction_numerical': 0.0, 'mean_word_length': 2.409090909090909, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6869691', 'n_tokens_mistral': 1002, 'n_tokens_neox': 975, 'n_words': 202}