Class: Dry::Struct::StructBuilder
- Inherits:
-
Types::Compiler
- Object
- Types::Compiler
- 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.
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(Dry::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
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dry/struct/struct_builder.rb', line 17 def call(attr_name, type, &block) const_name = const_name(type, attr_name) check_name(const_name) new_type = Class.new(parent(type), &block) struct.const_set(const_name, new_type) if array?(type) type.of(new_type) else new_type end end |