lib/logux/model/updates_deprecator.rb in logux_rails-0.1.0 vs lib/logux/model/updates_deprecator.rb in logux_rails-0.2.0

- old
+ new

@@ -3,21 +3,19 @@ module Logux module Model class UpdatesDeprecator EVENT = 'logux.insecure_update' - class << self - def watch(args = {}, &block) - new(args).watch(&block) - end + def self.call(options = {}, &block) + new(options).call(&block) end - def initialize(level: :warn) - @level = level + def initialize(options) + @options = options end - def watch(&block) + def call(&block) callback = lambda(&method(:handle_insecure_update)) ActiveSupport::Notifications.subscribed(callback, EVENT, &block) end private @@ -40,15 +38,21 @@ message = <<~TEXT Logux tracked #{pluralized_attributes} (#{insecure_attributes.join(', ')}) should be updated using model.logux.update(...) TEXT - case @level + case level when :warn ActiveSupport::Deprecation.warn(message) when :error raise InsecureUpdateError, message end + end + + DEFAULT_LEVEL = :warn + + def level + @options[:level] || DEFAULT_LEVEL end end end end