Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/samuelgiles/duckface
A collection of tools to enforce duck typing based interfaces in Ruby.
https://github.com/samuelgiles/duckface
duck-typing interfaces ruby type-safety
Last synced: 2 months ago
JSON representation
A collection of tools to enforce duck typing based interfaces in Ruby.
- Host: GitHub
- URL: https://github.com/samuelgiles/duckface
- Owner: samuelgiles
- License: mit
- Created: 2018-05-27T20:16:58.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-10-19T10:34:47.000Z (about 3 years ago)
- Last Synced: 2024-10-20T07:28:07.050Z (2 months ago)
- Topics: duck-typing, interfaces, ruby, type-safety
- Language: Ruby
- Homepage:
- Size: 37.1 KB
- Stars: 10
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: MIT-LICENSE
Awesome Lists containing this project
README
![duckface](https://user-images.githubusercontent.com/2643026/40590182-811ac3bc-61f2-11e8-814a-b235c51fd52c.jpg)
# Duckface [![CircleCI](https://circleci.com/gh/samuelgiles/duckface.svg?style=svg)](https://circleci.com/gh/samuelgiles/duckface)
A collection of tools to enforce duck typing based interfaces in Ruby.
## Install
From gem:
```
gem 'duckface-interfaces', require: 'duckface'
```From source:
```
gem 'duckface-interfaces', require: 'duckface', git: '[email protected]:samuelgiles/duckface.git'
```## Configure
### RSpec
`spec/spec_helper.rb`
```ruby
require 'duckface/rspec'
```## Usage
### Define an interface
```ruby
require 'duckface'module MyInterface
extend Duckface::ActsAsInterfaceexclude_methods_from_interface_enforcement :ignoreable_method_a, :ignoreable_method_b
def say_my_name(_name)
raise NotImplementedMethod
enddef ignoreable_method_a
puts 'I can be ignored'
enddef ignoreable_method_b
puts 'And so can I'
end
end
```### Define an implementation
```ruby
require 'duckface'class MyImplementation
implements_interface MyInterfacedef say_my_name(name)
puts name
end
end
```### Test that an implementation correctly implements an interface
```ruby
require 'spec_helper'describe MyImplementation
it_behaves_like 'it implements', MyInterface
end
```If it fails you'll get messages pointing out where you've gone wrong:
```ruby
Failures:1) MyImplementation behaves like it implements MyInterface correctly
Failure/Error: expect(check_session.successful?).to be(true), formatted_message(check_session)expected to correctly implement MyInterface:
- say_my_name is not present
```