Sha256: 492d7315e4cb6560409ffd1073f3281a8016d0961b3faca90920b2fe698ee304
Contents?: true
Size: 1.09 KB
Versions: 19
Compression:
Stored size: 1.09 KB
Contents
class ReeDto::DtoBuilder include Ree::Contracts::Core include Ree::Contracts::ArgContracts include Ree::LinkDSL link "ree_dto/dto/field_meta", -> { FieldMeta } link "ree_dto/dto/collection_meta", -> { CollectionMeta } attr_reader :fields, :collections def initialize(klass) @klass = klass @fields = [] @collections = [] end contract(Symbol, Any, Kwargs[setter: Bool, default: Any] => FieldMeta) 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 contract Symbol, Any, Optblock => CollectionMeta 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 end
Version data entries
19 entries across 19 versions & 1 rubygems