lib/alba/resource.rb in alba-3.2.0 vs lib/alba/resource.rb in alba-3.3.0
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
require_relative 'association'
require_relative 'conditional_attribute'
require_relative 'constants'
require_relative 'type'
require_relative 'typed_attribute'
@@ -232,26 +234,10 @@
end
def transform_key(key)
return Alba.regularize_key(key) if @_transform_type == :none || key.nil? || key.empty? # We can skip transformation
- inflector = Alba.inflector
- raise Alba::Error, 'Inflector is nil. You must set inflector before transforming keys.' unless inflector
-
- Alba.regularize_key(_transform_key(inflector, key.to_s))
- end
-
- def _transform_key(inflector, key)
- case @_transform_type
- when :camel then inflector.camelize(key)
- when :lower_camel then inflector.camelize_lower(key)
- when :dash then inflector.dasherize(key)
- when :snake then inflector.underscore(key)
- else
- # :nocov:
- raise Alba::Error, "Unknown transform type: #{@_transform_type}"
- # :nocov:
- end
+ Alba.transform_key(key, transform_type: @_transform_type)
end
def fetch_attribute(obj, key, attribute) # rubocop:disable Metrics/CyclomaticComplexity
value = case attribute
when Symbol then fetch_attribute_from_object_and_resource(obj, attribute)