Class: ReeDto::DtoBuilder
- Inherits:
-
Object
- Object
- ReeDto::DtoBuilder
- Includes:
- Ree::Contracts::ArgContracts, Ree::Contracts::Core, Ree::LinkDSL
- Defined in:
- lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_builder.rb
Instance Attribute Summary collapse
-
#collections ⇒ Object
readonly
Returns the value of attribute collections.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
Instance Method Summary collapse
- #collection(name, contract, &proc) ⇒ Object
- #field(name, contract, setter: true, default: FieldMeta::NONE) ⇒ Object
-
#initialize(klass) ⇒ DtoBuilder
constructor
A new instance of DtoBuilder.
Constructor Details
#initialize(klass) ⇒ DtoBuilder
Returns a new instance of DtoBuilder.
11 12 13 14 15 |
# File 'lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_builder.rb', line 11 def initialize(klass) @klass = klass @fields = [] @collections = [] end |
Instance Attribute Details
#collections ⇒ Object (readonly)
Returns the value of attribute collections.
9 10 11 |
# File 'lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_builder.rb', line 9 def collections @collections end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
9 10 11 |
# File 'lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_builder.rb', line 9 def fields @fields end |
Instance Method Details
#collection(name, contract, &proc) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_builder.rb', line 31 def collection(name, contract, &proc) existing = @collections.find { _1.name == name } if existing raise ArgumentError.new("collection :#{name} already defined for #{@klass}") end collection = CollectionMeta.new(name, contract, proc) @collections.push(collection) collection end |
#field(name, contract, setter: true, default: FieldMeta::NONE) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_builder.rb', line 18 def field(name, contract, setter: true, default: FieldMeta::NONE) existing = @fields.find { _1.name == name } if existing raise ArgumentError.new("field :#{name} already defined for #{@klass}") end field = FieldMeta.new(name, contract, setter, default) @fields << field field end |