Created
September 18, 2014 12:52
-
-
Save baphled/bb06a977aede91967afe to your computer and use it in GitHub Desktop.
This file contains 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
class DateOfBirth | |
include Virtus.model | |
attribute :year, Integer | |
attribute :month, Integer | |
attribute :year, Integer | |
def to_s | |
Date.new year, month, day | |
end | |
end | |
class Person | |
include Virtus.model | |
attribute :dob, DateOfBirth | |
end | |
class Salary | |
include Virtus.model | |
attribute :amount | |
attribute :frequency | |
end | |
class Contribution | |
include Virtus.model | |
attribute :value | |
attribute :frequency | |
# | |
# Let the object tell us what data type we are using | |
# | |
# Need activesupport to do this bit of magic | |
# | |
def datatype | |
__model__.snakecase.split '_' | |
end | |
end | |
class ContributionPercentage < Contribution | |
end | |
class ContributionCurrency < Contribution | |
end | |
class Pot | |
attribute :value | |
end | |
class Inputs | |
include Virtus.model | |
include ActiveModel::Model | |
attribute :person, Person | |
attribute :salary, Salary | |
attribute :employee_contribution, Contribution | |
attribute :employer_contribution, Contribution | |
attribute :contribution_pot, ContributionPot | |
attribute :target_income, TargetIncome | |
attribute :delay_contribution, DelayContribution | |
attribute :pots, Array[Pot] | |
end | |
input = Input.new params | |
input.valid? | |
input.errors | |
input.attributes | |
input.employee_contribution.valid? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment