Class: Structor::Builder

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Builder

Returns a new instance of Builder.



5
6
7
8
# File 'lib/structor/builder.rb', line 5

def initialize(&block)
  @nodes = {}
  instance_eval(&block)
end

Instance Attribute Details

#nodesObject

Returns the value of attribute nodes.



3
4
5
# File 'lib/structor/builder.rb', line 3

def nodes
  @nodes
end

Instance Method Details

#optional(name, type = :hash, &block) ⇒ Object



14
15
16
# File 'lib/structor/builder.rb', line 14

def optional(name, type = :hash, &block)
  @nodes[name] = Node.new(type, false, &block)
end

#requires(name, type = :hash, &block) ⇒ Object



10
11
12
# File 'lib/structor/builder.rb', line 10

def requires(name, type = :hash, &block)
  @nodes[name] = Node.new(type, true, &block)
end