Sha256: 4fa8e1d1f670928397c25d4faae6e8a653beeff08565943c5c2e81ad0f328971

Contents?: true

Size: 917 Bytes

Versions: 3

Compression:

Stored size: 917 Bytes

Contents

require_relative 'template'

module Immunio
  # Hook for the `ActiveSupport::Hash#to_query`.
  # Use case: building a url within a decorator that renders a partial with an interpolation.
  module ActiveSupportHooks
    extend ActiveSupport::Concern

    included do
      Immunio::Utils.alias_method_chain self, :to_query, :immunio
    end

    def to_query_with_immunio(namespace = nil)
      escaped_string = to_query_without_immunio(namespace)
      Request.time "plugin", "#{Module.nesting[0]}::#{__method__}" do
        # Our markers got escaped, so un-unescaped them back.
        escaped_string.gsub!(
          Immunio::Template::ENCODED_IMMUNIO_TOKENS_RE,
          "{immunio-\\1:\\2:\\3}\\4{/immunio-\\1:\\2:\\3}")
      end
      escaped_string
    end
  end
end

ActiveSupport.on_load(:after_initialize) do
  # Wait for ActiveSupport core ext to load
  Hash.send :include, Immunio::ActiveSupportHooks
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
immunio-2.0.4 lib/immunio/plugins/action_view/active_support_hash.rb
immunio-2.0.3 lib/immunio/plugins/action_view/active_support_hash.rb
immunio-2.0.2 lib/immunio/plugins/action_view/active_support_hash.rb