lib/alba.rb in alba-3.0.3 vs lib/alba.rb in alba-3.1.0

- old
+ new

@@ -112,18 +112,15 @@ # @return [Class<Alba::Resource>] resource class def infer_resource_class(name, nesting: nil) raise Alba::Error, 'Inference is disabled so Alba cannot infer resource name. Set inflector before use.' unless Alba.inflector const_parent = nesting.nil? ? Object : Object.const_get(nesting) - # rubocop-performance 1.20.2 might resolve this - # rubocop:disable Performance/StringIdentifierArgument begin const_parent.const_get("#{inflector.classify(name)}Resource") rescue NameError # Retry for serializer const_parent.const_get("#{inflector.classify(name)}Serializer") end - # rubocop:enable Performance/StringIdentifierArgument end # Configure Alba to symbolize keys def symbolize_keys! @symbolize_keys = true @@ -240,14 +237,16 @@ end inflector end - def register_default_types # rubocop:disable Metrics/AbcSize - register_type(:String, check: ->(obj) { obj.is_a?(String) }, converter: ->(obj) { obj.to_s }) - register_type(String, check: ->(obj) { obj.is_a?(String) }, converter: ->(obj) { obj.to_s }) - register_type(:Integer, check: ->(obj) { obj.is_a?(Integer) }, converter: ->(obj) { Integer(obj) }) - register_type(Integer, check: ->(obj) { obj.is_a?(Integer) }, converter: ->(obj) { Integer(obj) }) + def register_default_types + [String, :String].each do |t| + register_type(t, check: ->(obj) { obj.is_a?(String) }, converter: ->(obj) { obj.to_s }) + end + [Integer, :Integer].each do |t| + register_type(t, check: ->(obj) { obj.is_a?(Integer) }, converter: ->(obj) { Integer(obj) }) + end register_type(:Boolean, check: ->(obj) { [true, false].include?(obj) }, converter: ->(obj) { !!obj }) end end reset!