Sha256: 2f08165ce4f5b5df9682f6aeb3c57723891c27388a821918394fc26baa17b1b1

Contents?: true

Size: 679 Bytes

Versions: 1

Compression:

Stored size: 679 Bytes

Contents

class Tram::Policy
  if Object.const_defined? "ActiveSupport::Inflector"
    Inflector = ActiveSupport::Inflector
  elsif Object.const_defined? "Inflecto"
    Inflector = ::Inflecto
  else
    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

1 entries across 1 versions & 1 rubygems

Version Path
tram-policy-0.2.0 lib/tram/policy/inflector.rb