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

Version Path
ree_lib-1.0.124 lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_builder.rb
ree_lib-1.0.123 lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_builder.rb
ree_lib-1.0.122 lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_builder.rb
ree_lib-1.0.121 lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_builder.rb
ree_lib-1.0.120 lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_builder.rb
ree_lib-1.0.119 lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_builder.rb
ree_lib-1.0.118 lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_builder.rb
ree_lib-1.0.117 lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_builder.rb
ree_lib-1.0.116 lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_builder.rb
ree_lib-1.0.115 lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_builder.rb
ree_lib-1.0.114 lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_builder.rb
ree_lib-1.0.113 lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_builder.rb
ree_lib-1.0.112 lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_builder.rb
ree_lib-1.0.111 lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_builder.rb
ree_lib-1.0.110 lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_builder.rb
ree_lib-1.0.109 lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_builder.rb
ree_lib-1.0.108 lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_builder.rb
ree_lib-1.0.107 lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_builder.rb
ree_lib-1.0.106 lib/ree_lib/packages/ree_dto/package/ree_dto/dto/dto_builder.rb