lib/wcc/contentful/model_builder.rb in wcc-contentful-0.2.0 vs lib/wcc/contentful/model_builder.rb in wcc-contentful-0.2.1
- old
+ new
@@ -56,11 +56,11 @@
filter.transform_keys! { |k| k.to_s.camelize(:lower) }
bad_fields = filter.keys.reject { |k| fields.include?(k) }
raise ArgumentError, "These fields do not exist: #{bad_fields}" unless bad_fields.empty?
result = WCC::Contentful::Model.store.find_by(content_type: content_type, filter: filter)
- new(result, context)
+ new(result, context) if result
end
define_singleton_method(:inherited) do |subclass|
# only register if it's not already registered
return if WCC::Contentful::Model.registered?(typedef.content_type)
@@ -93,9 +93,12 @@
when :Int
raw_value = Integer(raw_value)
when :Float
raw_value = Float(raw_value)
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)
end
end