Sha256: 4fcb9cffb059114f09255551f4d5849f0efd385699c45a3bb90fad61d3d77e75
Contents?: true
Size: 966 Bytes
Versions: 1
Compression:
Stored size: 966 Bytes
Contents
module Alba # Transform keys using `ActiveSupport::Inflector` module KeyTransformer begin require 'active_support/inflector' rescue LoadError raise ::Alba::Error, 'To use transform_keys, please install `ActiveSupport` gem.' end module_function # Transform key as given transform_type # # @params key [String] key to be transformed # @params transform_type [Symbol] transform type # @return [String] transformed key # @raise [Alba::Error] when transform_type is not supported def transform(key, transform_type) case transform_type when :camel ActiveSupport::Inflector.camelize(key) when :lower_camel ActiveSupport::Inflector.camelize(key, false) when :dash ActiveSupport::Inflector.dasherize(key) else raise ::Alba::Error, "Unknown transform_type: #{transform_type}. Supported transform_type are :camel and :dash." end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
alba-0.13.0 | lib/alba/key_transformer.rb |