lib/avromatic/model/attributes.rb in avromatic-2.0.1 vs lib/avromatic/model/attributes.rb in avromatic-2.1.0
- old
+ new
@@ -19,18 +19,19 @@
super("Optional field not allowed: #{field}")
end
end
class AttributeDefinition
- attr_reader :name, :setter_name, :type, :field, :default, :owner
+ attr_reader :name, :name_string, :setter_name, :type, :field, :default, :owner
delegate :serialize, to: :type
def initialize(owner:, field:, type:)
@owner = owner
@field = field
@type = type
@name = field.name.to_sym
+ @name_string = field.name.to_s.dup.freeze
@setter_name = "#{field.name}=".to_sym
@default = if field.default == :no_default
nil
elsif field.default.duplicable?
field.default.dup.deep_freeze
@@ -77,12 +78,12 @@
attribute_definitions.each do |attribute_name, attribute_definition|
if data.include?(attribute_name)
valid_keys << attribute_name
value = data.fetch(attribute_name)
send(attribute_definition.setter_name, value)
- elsif data.include?(attribute_name.to_s)
+ elsif data.include?(attribute_definition.name_string)
valid_keys << attribute_name
- value = data[attribute_name.to_s]
+ value = data[attribute_definition.name_string]
send(attribute_definition.setter_name, value)
elsif !attributes.include?(attribute_name)
send(attribute_definition.setter_name, attribute_definition.default)
end
end