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

strict: true when attribute is being set. #328

Open
neumachen opened this issue Jul 29, 2015 · 3 comments
Open

strict: true when attribute is being set. #328

neumachen opened this issue Jul 29, 2015 · 3 comments

Comments

@neumachen
Copy link

neumachen commented Jul 29, 2015

How is this achieved when setting strict mode on?

Let's say I have a sample class:

class Banana
  include Virtus.model

  attribute :origin, Country
  attribute :source, SourcesVendor

end

I only want to enforce coercion when an attribute is set either on initialize or during an instance.

How would this be achieved with Virtus?

@neumachen
Copy link
Author

Is this currently possible or would this be a feature we need to request?

@grantspeelman
Copy link

I don't really see the use case for this?

@grantspeelman
Copy link

I know you can set strict per attribute

class Banana
  include Virtus.model

  attribute :origin, Country, strict: true
  attribute :source, SourcesVendor

end

but not sure why you would want

Banana.new(:origin => 'country')`

but not

b = Banana.new
b.origin = 'country'

or vice versa to fail

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