Class: Dry::Struct::StructBuilder
- Defined in:
- lib/dry/struct/struct_builder.rb
Instance Attribute Summary collapse
-
#struct ⇒ Object
readonly
Returns the value of attribute struct.
Instance Method Summary collapse
- #call(attr_name, type) { ... } ⇒ Object
-
#initialize(struct) ⇒ StructBuilder
constructor
A new instance of StructBuilder.
Methods inherited from Compiler
Constructor Details
#initialize(struct) ⇒ StructBuilder
Returns a new instance of StructBuilder.
9 10 11 12 |
# File 'lib/dry/struct/struct_builder.rb', line 9 def initialize(struct) super(Types) @struct = struct end |
Instance Attribute Details
#struct ⇒ Object (readonly)
Returns the value of attribute struct.
7 8 9 |
# File 'lib/dry/struct/struct_builder.rb', line 7 def struct @struct end |
Instance Method Details
#call(attr_name, type) { ... } ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/dry/struct/struct_builder.rb', line 18 def call(attr_name, type, &block) const_name = const_name(type, attr_name) check_name(const_name) builder = self parent = parent(type) new_type = ::Class.new(Undefined.default(parent, struct.abstract_class)) do if Undefined.equal?(parent) schema builder.struct.schema.clear end class_exec(&block) end struct.const_set(const_name, new_type) if array?(type) type.of(new_type) elsif optional?(type) new_type.optional else new_type end end |