hoodoo icon indicating copy to clipboard operation
hoodoo copied to clipboard

Allow a schema to be aliased

Open davidoram opened this issue 7 years ago • 1 comments

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",
  ...
}

davidoram avatar Dec 08 '17 01:12 davidoram