0

I just wrote a custom DM type to help me with this thing. Inherits from String, and all that jazz. Just now I'd like to have a default validation. So, something that I as a user don't need to define, it is just implicitly there. For instance, for an attribute of Boolean type, if you pass something other than true or false, it invalidates it's object. I'd like to have something like that. Do you know whether this is possible, and where in the architecture to insert it at best?

ChuckE
  • 5,610
  • 4
  • 31
  • 59

1 Answers1

0

I think you can add it in the dump method, for example

def dump(value)
  if valid_type?(value)
    value
  else
    raise "Invalid type specified"
  end
end

def valid_type?(value)
  #your validation code
end

Other way is using one of the dm-validations

In your case it would be

#Skipping class Definition
property :something, Your_dm_type
validates_with_block :something do
  if condition
    true
  else
   [false, "Invalid property specified"]
end

Or other validations as per the requirement

Mudassir Ali
  • 7,913
  • 4
  • 32
  • 60