Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/oleander/dry-interface


https://github.com/oleander/dry-interface

Last synced: 2 months ago
JSON representation

Awesome Lists containing this project

README

        

# Dry::Interface [![Main](https://github.com/oleander/dry-interface/actions/workflows/main.yml/badge.svg)](https://github.com/oleander/dry-interface/actions/workflows/main.yml)

``` ruby
require "dry/interface"

class Animal < Dry::Interface
class Mammal < Concrete
attribute :id, Value(:mammal)
end

class Bird < Value
attribute :id, Value(:bird)
end

class Fish < Abstract
class Whale < Value
attribute :id, Value(:whale)
end

class Shark < Value
attribute :id, Value(:shark)
end
end
end

Animal.new(id: :mammal) # => Animal::Mammal
Animal.new(id: :shark) # => Animal::Fish::Shark
```