lib/materialist/materializer/internals/materializer.rb in materialist-3.7.0 vs lib/materialist/materializer/internals/materializer.rb in materialist-3.8.0

- old
+ new

@@ -57,11 +57,11 @@ def materialize_self? options.include? :model_class end def upsert_record - model_class.find_or_initialize_by(source_lookup(url)).tap do |entity| + model_class.find_or_initialize_by(source_lookup(url, resource)).tap do |entity| send_messages(before_upsert, entity) unless before_upsert.nil? before_upsert_with_payload&.each { |m| instance.send(m, entity, resource) } entity.update_attributes!(attributes) end end @@ -108,15 +108,15 @@ def source_key options.fetch(:source_key, :source_url) end - def url_parser - options[:url_parser] || ->url { url } + def source_key_parser + options[:source_key_parser] || ->(url, data) { url } end - def source_lookup(url) - @_source_lookup ||= { source_key => url_parser.call(url) } + def source_lookup(url, resource={}) + @_source_lookup ||= { source_key => source_key_parser.call(url, resource) } end def attributes mappings.map{ |m| m.map(resource) }.compact.reduce(&:merge) || {} end