virtus icon indicating copy to clipboard operation
virtus copied to clipboard

strict: true when attribute is being set.

Open neumachen opened this issue 10 years ago • 3 comments
trafficstars

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 avatar Jul 29 '15 14:07 neumachen

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

neumachen avatar Aug 09 '15 13:08 neumachen

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

grantspeelman avatar Aug 28 '15 08:08 grantspeelman

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

grantspeelman avatar Aug 28 '15 09:08 grantspeelman