Module: Assertion
- Defined in:
- lib/assertion.rb,
lib/assertion/base.rb,
lib/assertion/guard.rb,
lib/assertion/state.rb,
lib/assertion/inverter.rb,
lib/assertion/messages.rb,
lib/assertion/inversion.rb,
lib/assertion/attributes.rb,
lib/assertion/invalid_error.rb,
lib/assertion/transprocs/list.rb,
lib/assertion/transprocs/inflector.rb
Overview
The module allows declaring assertions (assertions) about various objects, and apply (validate) them to concrete data.
Defined Under Namespace
Modules: Attributes, Inflector, List, Messages Classes: Base, Guard, InvalidError, Inversion, Inverter, State
Class Method Summary collapse
-
.about(*attributes, &block) ⇒ Class
Builds the subclass of
Assertion::Basewith predefinedattributesand implementation of the#checkmethod. -
.guards(attribute = nil, &block) ⇒ Class
Builds the subclass of
Assertion::Guardwith given attribute (alias for theobject) and implementation of the#statemethod.
Class Method Details
.about(*attributes, &block) ⇒ Class
Builds the subclass of Assertion::Base with predefined attributes and implementation of the #check method.
70 71 72 73 74 75 76 |
# File 'lib/assertion.rb', line 70 def self.about(*attributes, &block) klass = Class.new(Base) klass.public_send(:attribute, attributes) klass.__send__(:define_method, :check, &block) if block_given? klass end |
.guards(attribute = nil, &block) ⇒ Class
Builds the subclass of Assertion::Guard with given attribute (alias for the object) and implementation of the #state method.
102 103 104 105 106 107 108 |
# File 'lib/assertion.rb', line 102 def self.guards(attribute = nil, &block) klass = Class.new(Guard) klass.public_send(:attribute, attribute) if attribute klass.__send__(:define_method, :state, &block) if block_given? klass end |