Class: Jet::Contract::Builder
- Inherits:
-
Object
- Object
- Jet::Contract::Builder
- Defined in:
- lib/jet/contract/builder.rb
Instance Attribute Summary collapse
-
#checks ⇒ Object
readonly
Returns the value of attribute checks.
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #attribute_builders ⇒ Object (also: #to_h)
- #call(*args) ⇒ Object
-
#initialize(attribute_builders = {}) ⇒ Builder
constructor
A new instance of Builder.
- #optional(key) ⇒ Object
- #required(key) ⇒ Object
Constructor Details
#initialize(attribute_builders = {}) ⇒ Builder
Returns a new instance of Builder.
8 9 10 |
# File 'lib/jet/contract/builder.rb', line 8 def initialize(attribute_builders = {}) @attribute_builders = attribute_builders.dup end |
Instance Attribute Details
#checks ⇒ Object (readonly)
Returns the value of attribute checks.
6 7 8 |
# File 'lib/jet/contract/builder.rb', line 6 def checks @checks end |
#types ⇒ Object (readonly)
Returns the value of attribute types.
6 7 8 |
# File 'lib/jet/contract/builder.rb', line 6 def types @types end |
Instance Method Details
#[](key) ⇒ Object
12 13 14 |
# File 'lib/jet/contract/builder.rb', line 12 def [](key) @attribute_builders[key] end |
#attribute_builders ⇒ Object Also known as: to_h
20 21 22 |
# File 'lib/jet/contract/builder.rb', line 20 def attribute_builders @attribute_builders.dup end |
#call(*args) ⇒ Object
16 17 18 |
# File 'lib/jet/contract/builder.rb', line 16 def call(*args) Contract.new(@attribute_builders.transform_values { |ab| ab.(*args) }) end |
#optional(key) ⇒ Object
25 26 27 |
# File 'lib/jet/contract/builder.rb', line 25 def optional(key) attribute_builder(key, false) end |
#required(key) ⇒ Object
29 30 31 |
# File 'lib/jet/contract/builder.rb', line 29 def required(key) attribute_builder(key, true) end |