Class: Jet::Contract::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/jet/contract/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#checksObject (readonly)

Returns the value of attribute checks.



6
7
8
# File 'lib/jet/contract/builder.rb', line 6

def checks
  @checks
end

#typesObject (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_buildersObject 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