Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README code not working #9

Closed
joevandyk opened this issue Jul 11, 2016 · 2 comments
Closed

README code not working #9

joevandyk opened this issue Jul 11, 2016 · 2 comments

Comments

@joevandyk
Copy link

require 'dry-initializer'

class User
  extend Dry::Initializer::Mixin

  param  :name,  type: String
  param  :role,  default: proc { 'customer' }
  option :admin, default: proc { false }
end
/Users/joe/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/dry-initializer-0.4.0/lib/dry/initializer/plugins/type_constraint.rb:9:in `call': String used as constraint for argument 'name' is not a dry-type. (Dry::Initializer::Errors::TypeConstraintError)
    from /Users/joe/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/dry-initializer-0.4.0/lib/dry/initializer/plugins/base.rb:18:in `call'
    from /Users/joe/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/dry-initializer-0.4.0/lib/dry/initializer/builder.rb:53:in `block in define'
    from /Users/joe/.rbenv/versions/2.3.1/lib/ruby/2.3.0/set.rb:306:in `each_key'
    from /Users/joe/.rbenv/versions/2.3.1/lib/ruby/2.3.0/set.rb:306:in `each'
    from /Users/joe/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/dry-initializer-0.4.0/lib/dry/initializer/builder.rb:53:in `map'
    from /Users/joe/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/dry-initializer-0.4.0/lib/dry/initializer/builder.rb:53:in `define'
    from /Users/joe/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/dry-initializer-0.4.0/lib/dry/initializer/mixin.rb:16:in `param'
    from test.rb:6:in `<class:User>'
    from test.rb:3:in `<main>'
@nepalez
Copy link
Member

nepalez commented Jul 11, 2016

@joevandyk The thing is that dry-initializer from v0.4.0 does not support plain types, only dry-types.

Your example could be re-writtten as

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

module Types
   include Dry::Types.module
end

class User
  extend Dry::Initializer::Mixin

  param  :name,  type: Types::Coercible::String
  param  :role,  default: proc { 'customer' }
  option :admin, default: proc { false }
end

tbh, I updated docs on dry-rb.org, but had not published them yet.

@joevandyk
Copy link
Author

well publish them then ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants