lib/materialist/materializer.rb in materialist-0.0.1 vs lib/materialist/materializer.rb in materialist-0.0.2

- old
+ new

@@ -1,5 +1,6 @@ +require 'active_support/inflector' require 'routemaster/api_client' module Materialist module Materializer @@ -60,10 +61,13 @@ def after_upsert(method_name) materialist_options[:after_upsert] = method_name end + def after_destroy(method_name) + materialist_options[:after_destroy] = method_name + end end class Materializer def initialize(url, klass) @@ -77,11 +81,15 @@ instance.send(after_upsert, entity) if after_upsert end end def destroy - model_class.where(source_url: url).destroy_all + model_class.find_by(source_url: url).tap do |entity| + entity.destroy!.tap do |entity| + instance.send(after_destroy, entity) if after_destroy + end if entity + end end private attr_reader :url, :instance, :options @@ -97,9 +105,13 @@ options.fetch :mapping end def after_upsert options[:after_upsert] + end + + def after_destroy + options[:after_destroy] end def model_class options.fetch(:model_class).to_s.classify.constantize end