class Logux::Model::UpdatesDeprecator
Constants
- DEFAULT_LEVEL
- EVENT
Public Class Methods
call(options = {}, &block)
click to toggle source
# File lib/logux/model/updates_deprecator.rb, line 8 def self.call(options = {}, &block) new(options).call(&block) end
new(options)
click to toggle source
# File lib/logux/model/updates_deprecator.rb, line 12 def initialize(options) @options = options end
Public Instance Methods
call(&block)
click to toggle source
# File lib/logux/model/updates_deprecator.rb, line 16 def call(&block) callback = lambda(&method(:handle_insecure_update)) ActiveSupport::Notifications.subscribed(callback, EVENT, &block) end
Private Instance Methods
handle_insecure_update(_, _, _, _, args)
click to toggle source
rubocop:disable Naming/UncommunicativeMethodParamName
# File lib/logux/model/updates_deprecator.rb, line 24 def handle_insecure_update(_, _, _, _, args) model = args[:model] attributes = model.changed.map(&:to_sym) - [:logux_fields_updated_at] insecure_attributes = attributes & model.class.logux_crdt_mapped_attributes return if insecure_attributes.empty? notify_about_insecure_update(insecure_attributes) end
level()
click to toggle source
# File lib/logux/model/updates_deprecator.rb, line 53 def level @options[:level] || DEFAULT_LEVEL end
notify_about_insecure_update(insecure_attributes)
click to toggle source
rubocop:enable Naming/UncommunicativeMethodParamName
# File lib/logux/model/updates_deprecator.rb, line 36 def notify_about_insecure_update(insecure_attributes) pluralized_attributes = 'attribute'.pluralize(insecure_attributes.count) message = <<~TEXT Logux tracked #{pluralized_attributes} (#{insecure_attributes.join(', ')}) should be updated using model.logux.update(...) TEXT case level when :warn ActiveSupport::Deprecation.warn(message) when :error raise InsecureUpdateError, message end end