lib/alba.rb in alba-1.1.0 vs lib/alba.rb in alba-1.2.0
- old
+ new
@@ -7,12 +7,15 @@
class Error < StandardError; end
# Error class for backend which is not supported
class UnsupportedBackend < Error; end
+ # Error class for type which is not supported
+ class UnsupportedType < Error; end
+
class << self
- attr_reader :backend, :encoder, :inferring, :_on_error
+ attr_reader :backend, :encoder, :inferring, :_on_error, :transforming_root_key
# Set the backend, which actually serializes object into JSON
#
# @param backend [#to_sym, nil] the name of the backend
# Possible values are `oj`, `active_support`, `default`, `json` and nil
@@ -64,10 +67,20 @@
raise ArgumentError, 'You must specify error handler with either Symbol or block' unless handler || block
@_on_error = handler || block
end
+ # Enable root key transformation
+ def enable_root_key_transformation!
+ @transforming_root_key = true
+ end
+
+ # Disable root key transformation
+ def disable_root_key_transformation!
+ @transforming_root_key = false
+ end
+
private
def set_encoder
@encoder = case @backend
when :oj, :oj_strict
@@ -107,6 +120,7 @@
end
end
@encoder = default_encoder
@_on_error = :raise
+ @transforming_root_key = false # TODO: This will be true since 2.0
end