Class: Assertion::Base
- Inherits:
-
Object
- Object
- Assertion::Base
- Extended by:
- Attributes
- Includes:
- Messages
- Defined in:
- lib/assertion/base.rb
Overview
The base class for assertions about some attributes
Every assertion should define a list of attributes to be checked and the [#check] method to apply the assertion to those attributes
The assertion call method provides the object, describing the state of the assertion applied to its attributes. The provided state carries the result of the checkup and a corresponding <error> message. Later it can be composed with other states to provide complex validation.
The class DSL also defines shortcuts:
- .[]
-
can be used to initialize the assertion for given attributes and
then apply it immediately with creation of the corresponding state.
- .not
-
can be used to provide the assertion opposite to the initial one.
Direct Known Subclasses
Constant Summary
Constants included from Messages
Messages::DICTIONARY, Messages::ROOT
Instance Attribute Summary collapse
-
#attributes ⇒ Hash
readonly
The hash of the allowed attributes having been initialized.
Class Method Summary collapse
-
.[](hash = {}) ⇒ Assertion::State
Initializes an assertion with some attributes (data) and then calls it.
-
.not ⇒ Assertion::Inverter
Initializes the intermediate inverter with
newand[]methods.
Instance Method Summary collapse
-
#call ⇒ Check::State
Calls the assertion checkup and returns the state of the assertion having been applied to the current attributes.
-
#initialize(args = {}) ⇒ Base
constructor
A new instance of Base.
Methods included from Attributes
Methods included from Messages
Constructor Details
#initialize(args = {}) ⇒ Base
Returns a new instance of Base.
102 103 104 105 106 |
# File 'lib/assertion/base.rb', line 102 def initialize(args = {}) @attributes = {} self.class.attributes.each { |name| __set_attribute__ name, args[name] } freeze end |
Instance Attribute Details
#attributes ⇒ Hash (readonly)
Returns The hash of the allowed attributes having been initialized.
99 100 101 |
# File 'lib/assertion/base.rb', line 99 def attributes @attributes end |
Class Method Details
.[](hash = {}) ⇒ Assertion::State
Initializes an assertion with some attributes (data) and then calls it
53 54 55 |
# File 'lib/assertion/base.rb', line 53 def [](hash = {}) new(hash).call end |
.not ⇒ Assertion::Inverter
Initializes the intermediate inverter with new and [] methods
The inverter can be used to initialize the assertion, that describes just the opposite statement to the current one
74 75 76 |
# File 'lib/assertion/base.rb', line 74 def not Inverter.new(self) end |