Created
July 4, 2013 14:52
-
-
Save jmeirow/5928429 to your computer and use it in GitHub Desktop.
class-based schema
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'date' | |
| require_relative './persistence.rb' | |
| require_relative './mailing_address.rb' | |
| require_relative './government_id.rb' | |
| class Person < Persistence | |
| #----------------------------------------------- | |
| # initialize | |
| #----------------------------------------------- | |
| def initialize | |
| field = Person # this is just an 'alias' to the class name. It makes the initialization of 'fields' read better (field.required and field.type) | |
| fields = Hash.new | |
| fields[ Person.first_name ] = { field.required => true, field.type => String, field.location => field.local } | |
| fields[ Person.last_name ] = { field.required => true, field.type => String, field.location => field.local } | |
| fields[ Person.nick_name ] = { field.required => false, field.type => String, field.location => field.local } | |
| fields[ Person.government_id ] = { field.required => true, field.type => GovernmentId, field.location => field.local } | |
| fields[ Person.date_of_birth ] = { field.required => true, field.type => Date, field.location => field.local } | |
| fields[ Person.date_of_death ] = { field.required => false, field.type => Date, field.location => field.local } | |
| fields[ Person.mailing_address ] = { field.required => false, field.type => MailingAddress, field.location => field.remote } | |
| super fields | |
| end | |
| #----------------------------------------------- | |
| # aggregate_type | |
| #----------------------------------------------- | |
| def self.aggregate_type | |
| 'person' | |
| end | |
| #----------------------------------------------- | |
| # field names | |
| #----------------------------------------------- | |
| def self.first_name | |
| 'first_name' | |
| end | |
| def self.last_name | |
| 'last_name' | |
| end | |
| def self.nick_name | |
| 'nick_name' | |
| end | |
| def self.government_id | |
| 'government_id' | |
| end | |
| def self.date_of_birth | |
| 'date_of_birth' | |
| end | |
| def self.date_of_death | |
| 'date_of_death' | |
| end | |
| def self.mailing_address | |
| 'mailing_address' | |
| end | |
| #----------------------------------------------- | |
| # set lookup value | |
| #----------------------------------------------- | |
| def set_aggregate_lookup_value | |
| @data['aggregate_lookup_value'] = government_id.value | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment