Sha256: 784e02e724c05d9a3bfdd708d7821a30055f83cca3ba1e985ab877b2ad6acf59

Contents?: true

Size: 1.9 KB

Versions: 6

Compression:

Stored size: 1.9 KB

Contents

# frozen_string_literal: true

begin
  require 'active_support/inflector'
  require 'active_support/core_ext/module/delegation'
rescue LoadError
  raise Alba::Error, 'To use default inflector, please install `ActiveSupport` gem.'
end

module Alba
  # This module has two purposes.
  # One is that we require `active_support/inflector` in this module so that we don't do that all over the place.
  # Another is that `ActiveSupport::Inflector` doesn't have `camelize_lower` method that we want it to have, so this module works as an adapter.
  module DefaultInflector
    class << self
      # @!method camelize(key)
      #   @see https://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-camelize ActiveSupport::Inflector#camelize
      # @!method dasherize(key)
      #   @see https://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-dasherize ActiveSupport::Inflector#dasherize
      # @!method underscore(key)
      #   @see https://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-underscore ActiveSupport::Inflector#underscore
      # @!method classify(key)
      #   @see https://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-classify ActiveSupport::Inflector#classify
      # @!method demodulize(key)
      #   @see https://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-demodulize ActiveSupport::Inflector#demodulize
      # @!method pluralize(key)
      #   @see https://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-pluralize ActiveSupport::Inflector#pluralize
      delegate :camelize, :dasherize, :underscore, :classify, :demodulize, :pluralize, to: ActiveSupport::Inflector
    end

    # Camelizes a key, 1st letter lowercase
    #
    # @param key [String] key to be camelized
    # @return [String] camelized key
    def self.camelize_lower(key)
      ActiveSupport::Inflector.camelize(key, false)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
alba-3.5.0 lib/alba/default_inflector.rb
alba-3.4.0 lib/alba/default_inflector.rb
alba-3.3.3 lib/alba/default_inflector.rb
alba-3.3.2 lib/alba/default_inflector.rb
alba-3.3.1 lib/alba/default_inflector.rb
alba-3.3.0 lib/alba/default_inflector.rb