lib/wcc/contentful/model_builder.rb in wcc-contentful-1.2.0 vs lib/wcc/contentful/model_builder.rb in wcc-contentful-1.2.1

- old
+ new

@@ -59,11 +59,11 @@ define_method(:initialize) do |raw, context = nil| ct = content_type_from_raw(raw) if ct != typedef.content_type raise ArgumentError, 'Wrong Content Type - ' \ - "'#{raw.dig('sys', 'id')}' is a #{ct}, expected #{typedef.content_type}" + "'#{raw.dig('sys', 'id')}' is a #{ct}, expected #{typedef.content_type}" end @raw = raw.freeze created_at = raw.dig('sys', 'createdAt') created_at = Time.parse(created_at) if created_at.present? @@ -105,29 +105,30 @@ end elsif f.array # array fields need to resolve to an empty array when nothing is there raw_value = [] end - instance_variable_set('@' + f.name, raw_value) + instance_variable_set("@#{f.name}", raw_value) end end attr_reader :sys attr_reader :raw + delegate :id, to: :sys delegate :created_at, to: :sys delegate :updated_at, to: :sys delegate :revision, to: :sys delegate :space, to: :sys # Make a field for each column: typedef.fields.each_value do |f| name = f.name - var_name = '@' + name + var_name = "@#{name}" case f.type when :Asset, :Link define_method(name) do - val = instance_variable_get(var_name + '_resolved') + val = instance_variable_get("#{var_name}_resolved") return val if val.present? _resolve_field(name) end