class Shoulda::Matchers::ActiveModel::Qualifiers::IgnoreInterferenceByWriter

@private

Attributes

condition[R]
setting[R]

Public Class Methods

new(argument = :always) click to toggle source
# File lib/shoulda/matchers/active_model/qualifiers/ignore_interference_by_writer.rb, line 9
def initialize(argument = :always)
  set(argument)
  @changed = false
end

Public Instance Methods

always?() click to toggle source
# File lib/shoulda/matchers/active_model/qualifiers/ignore_interference_by_writer.rb, line 62
def always?
  setting == :always
end
changed?() click to toggle source
# File lib/shoulda/matchers/active_model/qualifiers/ignore_interference_by_writer.rb, line 70
def changed?
  @changed
end
considering?(value) click to toggle source
# File lib/shoulda/matchers/active_model/qualifiers/ignore_interference_by_writer.rb, line 54
def considering?(value)
  case setting
  when :always then true
  when :never then false
  else condition_matches?(value)
  end
end
default_to(argument) click to toggle source
# File lib/shoulda/matchers/active_model/qualifiers/ignore_interference_by_writer.rb, line 42
def default_to(argument)
  temporary_ignore_interference_by_writer =
    IgnoreInterferenceByWriter.new(argument)

  unless changed?
    @setting = temporary_ignore_interference_by_writer.setting
    @condition = temporary_ignore_interference_by_writer.condition
  end

  self
end
never?() click to toggle source
# File lib/shoulda/matchers/active_model/qualifiers/ignore_interference_by_writer.rb, line 66
def never?
  setting == :never
end
set(argument) click to toggle source
# File lib/shoulda/matchers/active_model/qualifiers/ignore_interference_by_writer.rb, line 14
def set(argument)
  if argument.is_a?(self.class)
    @setting = argument.setting
    @condition = argument.condition
  else
    case argument
    when true, :always
      @setting = :always
    when false, :never
      @setting = :never
    else
      @setting = :sometimes

      if argument.is_a?(Hash)
        @condition = argument.fetch(:when)
      else
        raise invalid_argument_error(argument)
      end
    end
  end

  @changed = true

  self
rescue KeyError
  raise invalid_argument_error(argument)
end

Private Instance Methods

condition_matches?(value) click to toggle source
# File lib/shoulda/matchers/active_model/qualifiers/ignore_interference_by_writer.rb, line 90
def condition_matches?(value)
  if condition.respond_to?(:call)
    condition.call(value)
  else
    value.public_send(condition)
  end
end
invalid_argument_error(invalid_argument) click to toggle source
# File lib/shoulda/matchers/active_model/qualifiers/ignore_interference_by_writer.rb, line 76
          def invalid_argument_error(invalid_argument)
            ArgumentError.new(<<-ERROR)
Unknown argument: #{invalid_argument.inspect}.

ignoring_interference_by_writer takes one of three arguments:

* A symbol, either :never or :always.
* A boolean, either true (which means always) or false (which means
  never).
* A hash with a single key, :when, and a single value, which is either
  the name of a method or a Proc.
            ERROR
          end