Revisions
-
nicholasjhenry revised this gist
Dec 22, 2011 . 1 changed file with 16 additions and 15 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -12,28 +12,26 @@ def config end # lib/pay_roll/services/pay_day_service.rb class PayRoll::PayDayService def initialize(date=Date.now) @date = date @employees = PayRoll.employee_directory.active @employees.each { |e| e.extend(Payable) } end def execute @employees.each do |e| if e.pay_date?(@date) pc = PayCheck.new(e.calculate_pay(@date)) e.send_pay(pc) end end end end # lib/pay_roll/roles/payable.rb module PayRoll::Payable def pay_date?(date) # ... end @@ -46,9 +44,12 @@ def send_pay(pay_check) ## Rails application # app/controllers/pay_day_controller.rb # Yes, this would make more sense to be run in a scheduled job, but wanted to show # an example of services used in a Rails controlle class PayDayController < ApplicationController def create PayRoll::PayDayService.new.execute redirect_to :back, :notice => "Pay day has been successfully completed" end end -
nicholasjhenry revised this gist
Dec 22, 2011 . 1 changed file with 34 additions and 35 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,33 +1,39 @@ ## PayRoll gem # lib/pay_roll.rb module PayRoll class << self attr_accessor :employee_directory def config yield self end end end end # lib/pay_roll/services/pay_day_service.rb module PayRoll class PayDayService def initialize(date=Date.now) @date = date @employees = PayRoll.employee_directory.active @employees.each { |e| e.extend(Payable) } end def execute @employees.each do |e| if e.pay_date?(@date) pc = PayCheck.new(e.calculate_pay(@date)) e.send_pay(pc) end end end end end # lib/pay_roll/roles/payable.rb module Payable def pay_date?(date) # ... end @@ -37,28 +43,21 @@ def send_pay(pay_check) end end ## Rails application # app/controllers/pay_day_controller.rb class PayDayController < ApplicationController def create PayRoll::PayDayService.new.execute end end # config/initializers/pay_roll.rb PayRoll.config do |config| employee_directory = Employee end # models/employee.rb class Employee < ActiveRecord::Base scope :active, where(:active => true) end -
nicholasjhenry revised this gist
Dec 22, 2011 . No changes.There are no files selected for viewing
-
nicholasjhenry revised this gist
Oct 27, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ # lib/pay_roll/pay_day_service.rb # Consider this Use Case as the Context in DCI # class PayRoll::PayDayService def initialize(date=Date.today) @date = date -
nicholasjhenry revised this gist
Oct 26, 2011 . 1 changed file with 16 additions and 28 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,23 +1,17 @@ ## PayRoll Application Gem # lib/pay_roll/pay_day_service.rb # Consider this Use Case as the Context in DCI # module PayRoll::PayDayService def initialize(date=Date.today) @date = date # Employee could be any data source from the host, # in this example Rails/Active Record # @employees ||= Employee.active @employees.each { |e| e.extend(PayCheckRecipient) } end def execute @@ -30,8 +24,10 @@ def execute end end # lib/pay_roll/pay_check_recipient.rb # Consider this the Role in DCI # module PayRoll::PayCheckRecipient def pay_date?(date) # ... end @@ -42,6 +38,7 @@ def send_pay(pay_check) end # lib/pay_roll/pay_check.rb # class PayRoll::PayCheck # ... end @@ -51,26 +48,17 @@ class PayRoll::PayCheck # app/controllers/pay_day_controller.rb # Yes, this would make more sense to be run in a scheduled job, but wanted to show # an example of services used in a Rails controller # class PayDayController < ApplicationController def create PayRoll::PayDayService.new.execute redirect_to :back, :notice => "Pay day has been successfully completed" end end # models/employee.rb # The data in DCI # class Employee < ActiveRecord::Base scope :active, where(:active => true) end -
nicholasjhenry revised this gist
Oct 24, 2011 . 1 changed file with 18 additions and 15 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -12,28 +12,26 @@ def config end # lib/pay_roll/pay_day_service.rb module PayRoll::PayDayService def initialize(date=Date.today) @date = date @employees ||= PayRoll.database.find_employees @employees.each { |e| e.extend(Payable) } end def execute @employees.each do |e| if e.pay_date?(@date) pc = PayCheck.new(e.calculate_pay(@date)) e.send_pay(pc) end end end end # lib/pay_roll/payable.rb module PayRoll::Payable def pay_date?(date) # ... end @@ -43,6 +41,11 @@ def send_pay(pay_check) end end # lib/pay_roll/pay_check.rb class PayRoll::PayCheck # ... end ## Rails application # app/controllers/pay_day_controller.rb -
nicholasjhenry revised this gist
Oct 23, 2011 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -57,11 +57,11 @@ def create # config/initializers/pay_roll.rb PayRoll.config do |config| database = PayRollDatabase.new end # models/pay_roll_database.rb class PayRollDatabase def find_employees Employee.active end -
nicholasjhenry revised this gist
Oct 23, 2011 . 1 changed file with 9 additions and 9 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,22 +3,22 @@ # lib/pay_roll.rb module PayRoll class << self attr_accessor :database def config yield self end end end end # lib/pay_roll/pay_day_service.rb module PayRoll class PayDayService def initialize(date=Date.today, options={}) @date = date @employees ||= PayRoll.database.find_employees @employees.each { |e| e.extend(Payable) } end def execute @@ -32,7 +32,7 @@ def execute end end # lib/pay_roll/payable.rb module Payable def pay_date?(date) # ... @@ -57,12 +57,12 @@ def create # config/initializers/pay_roll.rb PayRoll.config do |config| database = Database.new end # lib/database.rb class Database def find_employees Employee.active end end -
nicholasjhenry revised this gist
Oct 22, 2011 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -46,6 +46,8 @@ def send_pay(pay_check) ## Rails application # app/controllers/pay_day_controller.rb # Yes, this would make more sense to be run in a scheduled job, but wanted to show # an example of services used in a Rails controller class PayDayController < ApplicationController def create PayRoll::PayDayService.new.execute -
nicholasjhenry renamed this gist
Oct 22, 2011 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
nicholasjhenry revised this gist
Oct 22, 2011 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -49,6 +49,7 @@ def send_pay(pay_check) class PayDayController < ApplicationController def create PayRoll::PayDayService.new.execute redirect_to :back, :notice => "Pay day has been successfully completed" end end -
nicholasjhenry revised this gist
Oct 22, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -14,7 +14,7 @@ def config # lib/pay_roll/services/pay_day_service.rb module PayRoll class PayDayService def initialize(date=Date.today, options={}) @date = date options[:employees] ||= PayRoll.employee_directory.active -
nicholasjhenry revised this gist
Oct 22, 2011 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -18,7 +18,7 @@ def initialize(date=Date.now, options={}) @date = date options[:employees] ||= PayRoll.employee_directory.active @employees = options[:employees].each { |e| e.extend(Payable) } end def execute @@ -32,8 +32,8 @@ def execute end end # lib/pay_roll/roles/payable.rb module Payable def pay_date?(date) # ... end -
nicholasjhenry revised this gist
Oct 22, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -54,7 +54,7 @@ def create # config/initializers/pay_roll.rb PayRoll.config do |config| employee_directory = EmployeeDirectory.new # alternatively just use Employee model end # models/employee_directory.rb -
nicholasjhenry revised this gist
Oct 22, 2011 . 1 changed file with 43 additions and 13 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,24 @@ ## PayRoll gem # lib/pay_roll.rb module PayRoll class << self attr_accessor :employee_directory def config yield self end end end end # lib/pay_roll/services/pay_day_service.rb module PayRoll class PayDayService def initialize(date=Date.now, options={}) @date = date options[:employees] ||= PayRoll.employee_directory.active @employees = options[:employees].each { |e| e.extend(PayableEmployee) } end def execute @@ -18,23 +30,41 @@ def execute end end end end # lib/pay_roll/roles/payable_employee.rb module PayableEmployee def pay_date?(date) # ... end def send_pay(pay_check) # ... end end ## Rails application # app/controllers/pay_day_controller.rb class PayDayController < ApplicationController def create PayRoll::PayDayService.new.execute end end # config/initializers/pay_roll.rb PayRoll.config do |config| employee_directory = EmployeeDirectory.new end # models/employee_directory.rb class EmployeeDirectory def active Employee.active end end # models/employee.rb class Employee < ActiveRecord::Base scope :active, where(:active => true) end -
nicholasjhenry revised this gist
Oct 22, 2011 . 1 changed file with 10 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ # payroll gem module PayRoll class PayDayService < Service def initialize(date=Date.now, options={}) @@ -28,4 +30,11 @@ def send_pay(pay_check) end end # Rails application, pay_day_controller.rb class PayDayController < ApplicationController def create PayRoll::PayDayService.new(Employee.all).execute end end -
nicholasjhenry revised this gist
Oct 22, 2011 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,10 @@ module PayRoll class PayDayService < Service def initialize(date=Date.now, options={}) @date = date options[:employees] ||= datastore.find_all_active_employees @employees = options[:employees].each{|e| e.extend(Employee) } end def execute -
nicholasjhenry revised this gist
Oct 22, 2011 . 1 changed file with 6 additions and 9 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,8 @@ module PayRoll class PayDayService < Service def initialize(date=Date.now, employees=datastore.find_all_employees) @date = date @employees = employees.each{|e| e.extend(Employee) } end def execute @@ -14,13 +15,9 @@ def execute end end module PayableEmployee def pay_date?(date) # ... end def send_pay(pay_check) -
nicholasjhenry revised this gist
Oct 22, 2011 . 1 changed file with 28 additions and 10 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,14 +1,32 @@ module PayRoll class PayDayService def initialize(employees_attributes, date=Date.now) @employees = employees_attributes.collect {|ea| Employee.new(ea)} end def execute @employees.each do |e| if e.pay_date?(@date) pc = PayCheck.new(e.calculate_pay(@date)) e.send_pay(pc) end end end end class Employee def initialize(attributes) @attributes = attributes end def pay_date?(date) # ... @attributes.started_on_date end def send_pay(pay_check) # ... end end end PayRoll::PayDayService.new(Employee.all).execute -
nicholasjhenry created this gist
Oct 22, 2011 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ class PayDayService def initialize(employees, date) @employees, @date = employees, date end def execute @employees.each do |e| if e.pay_date?(@date) pc = PayCheck.new(e.calculate_pay(@date)) e.send_pay(pc) end end end end