Class: Expectant::Schema
- Inherits:
-
Object
- Object
- Expectant::Schema
- Defined in:
- lib/expectant/schema.rb
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#validators ⇒ Object
readonly
Returns the value of attribute validators.
Instance Method Summary collapse
- #add_field(expectation) ⇒ Object
- #add_validator(validator_def) ⇒ Object
- #contract ⇒ Object
- #duplicate ⇒ Object
- #freeze ⇒ Object
-
#initialize(name) ⇒ Schema
constructor
A new instance of Schema.
- #keys ⇒ Object
- #reset! ⇒ Object
Constructor Details
#initialize(name) ⇒ Schema
Returns a new instance of Schema.
9 10 11 12 13 14 |
# File 'lib/expectant/schema.rb', line 9 def initialize(name) @name = name @fields = [] @validators = [] @contract_class = nil end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
7 8 9 |
# File 'lib/expectant/schema.rb', line 7 def fields @fields end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/expectant/schema.rb', line 7 def name @name end |
#validators ⇒ Object (readonly)
Returns the value of attribute validators.
7 8 9 |
# File 'lib/expectant/schema.rb', line 7 def validators @validators end |
Instance Method Details
#add_field(expectation) ⇒ Object
31 32 33 34 |
# File 'lib/expectant/schema.rb', line 31 def add_field(expectation) @fields << expectation @contract_class = nil end |
#add_validator(validator_def) ⇒ Object
36 37 38 39 |
# File 'lib/expectant/schema.rb', line 36 def add_validator(validator_def) @validators << validator_def @contract_class = nil end |
#contract ⇒ Object
20 21 22 |
# File 'lib/expectant/schema.rb', line 20 def contract @contract_class ||= build_contract end |
#duplicate ⇒ Object
24 25 26 27 28 29 |
# File 'lib/expectant/schema.rb', line 24 def duplicate dup = self.class.new(@name) dup.instance_variable_set(:@fields, @fields.dup) dup.instance_variable_set(:@validators, @validators.dup) dup end |
#freeze ⇒ Object
41 42 43 44 45 |
# File 'lib/expectant/schema.rb', line 41 def freeze @fields.freeze @validators.freeze super end |
#keys ⇒ Object
16 17 18 |
# File 'lib/expectant/schema.rb', line 16 def keys @fields.map(&:name) end |
#reset! ⇒ Object
47 48 49 50 51 |
# File 'lib/expectant/schema.rb', line 47 def reset! @fields = [] @validators = [] @contract_class = nil end |