Class: Shaped::Shapes::Class
- Inherits:
-
Shaped::Shape
- Object
- Shaped::Shape
- Shaped::Shapes::Class
- Defined in:
- lib/shaped/shapes/class.rb
Instance Method Summary collapse
-
#initialize(expected_klass, validations = {}) ⇒ Class
constructor
A new instance of Class.
- #matched_by?(object) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(expected_klass, validations = {}) ⇒ Class
Returns a new instance of Class.
4 5 6 7 8 9 10 11 12 |
# File 'lib/shaped/shapes/class.rb', line 4 def initialize(expected_klass, validations = {}) if !expected_klass.is_a?(Class) raise(Shaped::InvalidShapeDescription, "A #{self.class} description must be a Class.") end @expected_klass = expected_klass @validations = validations @validator_klass = validator_klass(validations) end |
Instance Method Details
#matched_by?(object) ⇒ Boolean
14 15 16 |
# File 'lib/shaped/shapes/class.rb', line 14 def matched_by?(object) object.is_a?(@expected_klass) && validations_satisfied?(object) end |
#to_s ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/shaped/shapes/class.rb', line 18 def to_s if @validations.empty? @expected_klass.name else "#{@expected_klass} validating #{@validations}" end end |