Skip to content
DSL for building class initializer with params and options.
Ruby
Branch: master
Clone or download
Pull request Compare This branch is 11 commits behind dry-rb:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
benchmarks
lib
spec
.codeclimate.yml
.gitignore
.rspec
.rubocop.yml
.travis.yml
CHANGELOG.md
Gemfile
Guardfile
LICENSE.txt
README.md
Rakefile
dry-initializer.gemspec

README.md

dry-initializer Join the chat at https://gitter.im/dry-rb/chat

Gem Version Build Status Code Climate Test Coverage Inline docs

DSL for building class initializer with params and options.

Installation

Add this line to your application's Gemfile:

gem 'dry-initializer'

And then execute:

$ bundle

Or install it yourself as:

$ gem install dry-initializer

Synopsis

require 'dry-initializer'
require 'dry-types'

class User
  extend Dry::Initializer

  # Params of the initializer along with corresponding readers
  param  :name,  proc(&:to_s)
  param  :role,  default: -> { 'customer' }
  # Options of the initializer along with corresponding readers
  option :admin, default: -> { false }
  option :vip,   optional: true
end

# Defines the initializer with params and options
user = User.new 'Vladimir', 'admin', admin: true

# Defines readers for single attributes
user.name  # => 'Vladimir'
user.role  # => 'admin'
user.admin # => true
user.vip   # => Dry::Initializer::UNDEFINED

See full documentation on the Dry project official site

Benchmarks

The dry-initializer is pretty fast for rubies 2.3+ comparing to other libraries.

Compatibility

Tested under rubies compatible to MRI 2.3+.

Contributing

  • Fork the project
  • Create your feature branch (git checkout -b my-new-feature)
  • Add tests for it
  • Commit your changes (git commit -am '[UPDATE] Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create a new Pull Request

License

The gem is available as open source under the terms of the MIT License.

You can’t perform that action at this time.