Class: Shoulda::Matchers::ActiveModel::Qualifiers::IgnoreInterferenceByWriter
- Inherits:
-
Object
- Object
- Shoulda::Matchers::ActiveModel::Qualifiers::IgnoreInterferenceByWriter
- Defined in:
- lib/shoulda/matchers/active_model/qualifiers/ignore_interference_by_writer.rb
Instance Attribute Summary collapse
-
#condition ⇒ Object
readonly
Returns the value of attribute condition.
-
#setting ⇒ Object
readonly
Returns the value of attribute setting.
Instance Method Summary collapse
- #always? ⇒ Boolean
- #changed? ⇒ Boolean
- #considering?(value) ⇒ Boolean
- #default_to(argument) ⇒ Object
-
#initialize(argument = :always) ⇒ IgnoreInterferenceByWriter
constructor
A new instance of IgnoreInterferenceByWriter.
- #never? ⇒ Boolean
- #set(argument) ⇒ Object
Constructor Details
#initialize(argument = :always) ⇒ IgnoreInterferenceByWriter
Returns a new instance of IgnoreInterferenceByWriter.
9 10 11 12 |
# File 'lib/shoulda/matchers/active_model/qualifiers/ignore_interference_by_writer.rb', line 9 def initialize(argument = :always) set(argument) @changed = false end |
Instance Attribute Details
#condition ⇒ Object (readonly)
Returns the value of attribute condition.
7 8 9 |
# File 'lib/shoulda/matchers/active_model/qualifiers/ignore_interference_by_writer.rb', line 7 def condition @condition end |
#setting ⇒ Object (readonly)
Returns the value of attribute setting.
7 8 9 |
# File 'lib/shoulda/matchers/active_model/qualifiers/ignore_interference_by_writer.rb', line 7 def setting @setting end |
Instance Method Details
#always? ⇒ Boolean
62 63 64 |
# File 'lib/shoulda/matchers/active_model/qualifiers/ignore_interference_by_writer.rb', line 62 def always? setting == :always end |
#changed? ⇒ Boolean
70 71 72 |
# File 'lib/shoulda/matchers/active_model/qualifiers/ignore_interference_by_writer.rb', line 70 def changed? @changed end |
#considering?(value) ⇒ Boolean
54 55 56 57 58 59 60 |
# 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) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# 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? ⇒ Boolean
66 67 68 |
# File 'lib/shoulda/matchers/active_model/qualifiers/ignore_interference_by_writer.rb', line 66 def never? setting == :never end |
#set(argument) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# 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 |