hoodoo
hoodoo copied to clipboard
Allow a schema to be aliased
I want to use a schema, in two different contexts but have the definition shared. For example I have defined a phone number as:
class PhoneNumber < Hoodoo::Presenters::Base
schema do
string :country_code
string :area_code, :required => true
string :number, :required => true
end
...
end
and then have it used in the same schema with different prefixes for example:
class Person < Hoodoo::Presenters::Base
type PhoneNumber, :key_prefix => 'mobile_'
type PhoneNumber, :key_prefix => 'home_'
...
And resulting in data like:
{
"mobile_country_code": "+64",
"mobile_area_code": "21",
"mobile_number": "6453 3232",
"home_country_code": "+64",
"home_area_code": "4",
"home_number": "111 2234",
...
}