Sha256: d803944bfcf4b1940564d61529dcda4aef759233d47787816e774f58eb2f1757

Contents?: true

Size: 884 Bytes

Versions: 1

Compression:

Stored size: 884 Bytes

Contents

# frozen_string_literal: true

require 'fast_underscore/version'
require 'fast_underscore/fast_underscore'

module FastUnderscore
  # Hooks into ActiveSupport::Inflector and waits for the #underscore method to
  # be defined. When it is, it automatically redefines it by hooking into its
  # acronyms and then still calling the native extension.
  module ActiveSupportHook
    def method_added(method)
      return super if method != :underscore || !defined?(ActiveSupport)
      require 'active_support/version'

      if ActiveSupport::VERSION::MAJOR == 5 &&
         ActiveSupport::VERSION::MINOR >= 2
        require 'fast_underscore/ext/acronym_underscore_regex'
      else
        require 'fast_underscore/ext/acronym_regex'
      end
    end
  end
end

module ActiveSupport
  module Inflector
    class << self
      prepend FastUnderscore::ActiveSupportHook
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fast_underscore-0.2.0 lib/fast_underscore.rb