From a13cbf3741ab3033ce3a0b25c518d41abfa6af42 Mon Sep 17 00:00:00 2001 From: Benjamin Randolph Date: Fri, 12 Jul 2024 07:02:28 -0600 Subject: [PATCH] Refactor incomes methods in concern. --- app/controllers/concerns/taxed_income.rb | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/app/controllers/concerns/taxed_income.rb b/app/controllers/concerns/taxed_income.rb index 36e1569..b304953 100644 --- a/app/controllers/concerns/taxed_income.rb +++ b/app/controllers/concerns/taxed_income.rb @@ -3,18 +3,22 @@ module TaxedIncome extend ActiveSupport::Concern - def tax_on_salary - income = Income.find_by(income_type: "Salary") - IncomeTaxCalculatorService.new(income: income) - end - - def tax_on_hourly - income = Income.find_by(income_type: "Hourly") - IncomeTaxCalculatorService.new(income: income) + included do + before_action :salary_income, :hourly_income end def build_taxed_income_vars! @salary_taxed = tax_on_salary @hourly_taxed = tax_on_hourly end -end + + private + + def salary_income + @salary_income ||= Income.find_by(income_type: "Salary") + end + + def hourly_income + @hourly_income ||= Income.find_by(income_type: "Hourly") + end +end \ No newline at end of file