Sha256: 37b495f392a0904e4f0b61e928f87da2808b33c1714661b6293d79512496f610

Contents?: true

Size: 675 Bytes

Versions: 5

Compression:

Stored size: 675 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

5 entries across 5 versions & 1 rubygems

Version Path
tram-policy-0.1.1 lib/tram/policy/inflector.rb
tram-policy-0.1.0 lib/tram/policy/inflector.rb
tram-policy-0.0.3 lib/tram/policy/inflector.rb
tram-policy-0.0.2 lib/tram/policy/inflector.rb
tram-policy-0.0.1 lib/tram/policy/inflector.rb