Skip to content

Commit

Permalink
Uninstall callable gem, add callable module, configure to be used in …
Browse files Browse the repository at this point in the history
…application.
  • Loading branch information
neb417 committed Jul 12, 2024
1 parent a13cbf3 commit c20a660
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 16 deletions.
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ gem "net-http"

gem "data_migrate"

gem "callable"

group :development, :test do
gem "capybara"
gem "factory_bot_rails"
Expand Down
2 changes: 0 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ GEM
bootsnap (1.16.0)
msgpack (~> 1.2)
builder (3.2.4)
callable (0.0.5)
capybara (3.38.0)
addressable
matrix
Expand Down Expand Up @@ -305,7 +304,6 @@ PLATFORMS
DEPENDENCIES
annotate
bootsnap
callable
capybara
data_migrate
factory_bot_rails
Expand Down
30 changes: 22 additions & 8 deletions app/controllers/concerns/taxed_income.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,36 @@
module TaxedIncome
extend ActiveSupport::Concern

included do
before_action :salary_income, :hourly_income
end

def build_taxed_income_vars!
@salary_taxed = tax_on_salary
@hourly_taxed = tax_on_hourly
@salary_taxed = net_income(annual_income: salary_income)
@hourly_taxed = net_income(annual_income: hourly_income)
end

private

def salary_income
@salary_income ||= Income.find_by(income_type: "Salary")
@salary_income ||= Income.find_by(income_type: "Salary").weekly_income * 52
end

def hourly_income
@hourly_income ||= Income.find_by(income_type: "Hourly")
@hourly_income ||= Income.find_by(income_type: "Hourly").weekly_income * 52
end

def fica_tax(income:)
@fica_tax ||= FicaTaxCalculator.call(income: income)
end

def federal_tax(income:)
@federal_tax ||= FederalTaxCalculator.call(income: income)
end

def state_tax(income:)
@state_tax ||= StateTaxCalculator.call(income: income)
end

def net_income(annual_income:)
income = annual_income - (fica_tax(income:annual_income) + federal_tax(income:annual_income) + state_tax(income:annual_income))

@net_income ||= NetIncomeCalculator.call(annual_income: income)
end
end
2 changes: 1 addition & 1 deletion app/services/federal_tax_calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def initialize(income:)
self.income = income
end

def callable
def call
calculate
end

Expand Down
6 changes: 3 additions & 3 deletions app/services/state_tax_calculator.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
class StateTaxCalculator
include Callable

def initialize(state:, income:)
def initialize(income:)
self.income = income
self.state = state
end

# Colorado state tax rate is 4.4%
def call
income * 0.044
end

private

attr_accessor :income, :state
attr_accessor :income

end
4 changes: 4 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 7.0

# Load in all modules
config.autoload_paths << Rails.root.join('lib', 'modules')
config.eager_load_paths << Rails.root.join('lib', 'modules')

# Configuration for the application, engines, and railties goes here.
#
# These settings can be overridden in specific environments using the files
Expand Down
9 changes: 9 additions & 0 deletions lib/modules/callable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Callable
extend ActiveSupport::Concern

class_methods do
def call(**args)
new(**args).call
end
end
end

0 comments on commit c20a660

Please sign in to comment.