Created
September 11, 2017 22:58
-
-
Save kellysutton/add84a41ed3560c683d47fe5bf11991f to your computer and use it in GitHub Desktop.
Embracing Functional Programming in Ruby
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
def taxes | |
PayrollCalculator::Taxes.calculate( | |
@payroll.only_pay_and_location_data | |
) | |
end |
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
def taxes | |
PayrollCalculator::Taxes.calculate(@payroll) | |
end |
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
def paystubs | |
calculate_paystubs(taxes, ...) | |
end | |
def debits | |
calculate_debits(taxes, ...) | |
end | |
def taxes | |
@taxes ||= calculate_taxes(@payroll) | |
end |
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
def taxes | |
federal_taxes(@payroll) + | |
california_taxes(@payroll) + | |
new_york_taxes(@payroll) + | |
local_california_taxes(@payroll) + | |
local_new_york_taxes(@payroll) | |
end |
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
# app/models/payroll.rb | |
class Payroll < ActiveRecord::Base | |
end | |
# app/services/payroll_calculator/payroll.rb | |
class PayrollCalculator::Payroll < ValueObject | |
end |
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
class PayrollCalculator | |
def self.calculate(payroll) | |
new(payroll).calculate | |
end | |
def initialize(payroll) | |
@payroll = payroll | |
end | |
private_class_method :new | |
def calculate | |
PayrollResult.new( | |
payroll: payroll, | |
paystubs: paystubs, | |
taxes: taxes, | |
debits: debits | |
) | |
end | |
def paystubs | |
# ... | |
end | |
def taxes | |
# ... | |
end | |
def debits | |
# ... | |
end | |
end |
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
def taxes | |
federal_taxes(@payroll) + | |
california_taxes(@payroll) + | |
local_taxes(@payroll) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment