Sha256: 219f7f69ce756e2458659a7c4a344739a979e1c0cbac696e1285f638b548f942

Contents?: true

Size: 724 Bytes

Versions: 14

Compression:

Stored size: 724 Bytes

Contents

class Tram::Policy
  if Object.const_defined? "ActiveSupport::Inflector"
    # @private
    Inflector = ActiveSupport::Inflector
  elsif Object.const_defined? "Inflecto"
    # @private
    Inflector = ::Inflecto
  else
    # @private
    module Inflector
      def self.underscore(name)
        name&.dup&.tap do |n|
          n.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
          n.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
          n.gsub!("::", "/")
          n.tr!("-", "_")
          n.downcase!
        end
      end

      def self.camelize(name)
        name&.dup&.tap do |n|
          n.gsub!(/(?:\A|_+)(.)/)    { $1.upcase }
          n.gsub!(%r{(?:[/|-]+)(.)}) { "::#{$1.upcase}" }
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
tram-policy-2.2.0 lib/tram/policy/inflector.rb
tram-policy-2.1.0 lib/tram/policy/inflector.rb
tram-policy-2.0.1 lib/tram/policy/inflector.rb
tram-policy-2.0.0 lib/tram/policy/inflector.rb
tram-policy-1.0.1 lib/tram/policy/inflector.rb
tram-policy-1.0.0 lib/tram/policy/inflector.rb
tram-policy-0.4.0 lib/tram/policy/inflector.rb
tram-policy-0.3.1 lib/tram/policy/inflector.rb
tram-policy-0.3.0 lib/tram/policy/inflector.rb
tram-policy-0.2.5 lib/tram/policy/inflector.rb
tram-policy-0.2.4 lib/tram/policy/inflector.rb
tram-policy-0.2.3 lib/tram/policy/inflector.rb
tram-policy-0.2.2 lib/tram/policy/inflector.rb
tram-policy-0.2.1 lib/tram/policy/inflector.rb