lib/wcc/contentful/model_builder.rb in wcc-contentful-0.2.1 vs lib/wcc/contentful/model_builder.rb in wcc-contentful-0.2.2
- old
+ new
@@ -55,11 +55,17 @@
define_singleton_method(:find_by) do |filter, context = nil|
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)
+ result =
+ if defined?(context[:preview]) && context[:preview] == true
+ WCC::Contentful::Model.preview_store.find_by(content_type: content_type, filter: filter)
+ else
+ WCC::Contentful::Model.store.find_by(content_type: content_type, filter: filter)
+ end
+
new(result, context) if result
end
define_singleton_method(:inherited) do |subclass|
# only register if it's not already registered
@@ -87,10 +93,10 @@
typedef.fields.each_value do |f|
raw_value = raw.dig('fields', f.name, @locale)
if raw_value.present?
case f.type
when :DateTime
- raw_value = Time.zone.parse(raw_value)
+ raw_value = Time.parse(raw_value).localtime
when :Int
raw_value = Integer(raw_value)
when :Float
raw_value = Float(raw_value)
end