alba 1.0.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,31 +0,0 @@
1
- module Alba
2
- # Transform keys using `ActiveSupport::Inflector`
3
- module KeyTransformer
4
- begin
5
- require 'active_support/inflector'
6
- rescue LoadError
7
- raise ::Alba::Error, 'To use transform_keys, please install `ActiveSupport` gem.'
8
- end
9
-
10
- module_function
11
-
12
- # Transform key as given transform_type
13
- #
14
- # @params key [String] key to be transformed
15
- # @params transform_type [Symbol] transform type
16
- # @return [String] transformed key
17
- # @raise [Alba::Error] when transform_type is not supported
18
- def transform(key, transform_type)
19
- case transform_type
20
- when :camel
21
- ActiveSupport::Inflector.camelize(key)
22
- when :lower_camel
23
- ActiveSupport::Inflector.camelize(key, false)
24
- when :dash
25
- ActiveSupport::Inflector.dasherize(key)
26
- else
27
- raise ::Alba::Error, "Unknown transform_type: #{transform_type}. Supported transform_type are :camel, :lower_camel and :dash."
28
- end
29
- end
30
- end
31
- end