Created
December 22, 2011 00:57
-
-
Save jonsmock/1508427 to your computer and use it in GitHub Desktop.
Revisions
-
jonsmock revised this gist
Dec 22, 2011 . 1 changed file with 0 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 @@ -9,9 +9,6 @@ Questions that arise as I code something like this: - Which objects deserve presenters? - Should I allow HTML in my presenters? - Do partials help or do they actually hide complexity that should be - Is this amount of logic ok in a view, if it's tested? (Views are essentially methods, right?) -
jonsmock revised this gist
Dec 22, 2011 . 1 changed file with 15 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 @@ -1,18 +1,18 @@ This example is not my real app, but it's modeled pretty closely to it. My mom schedules a couple hundred employees at a local warehouse. In their system, a worker can earn "points" for being late or missing shifts. Here we have a sort of summary screen for my mom, who may need to follow up with new employees or discipline employees with concerning levels of points. Questions that arise as I code something like this: - Which objects deserve presenters? - Should I allow HTML in my presenters? - Do partials help or do they actually hide complexity that should be eliminated? - Do I sometimes take the Law of Demeter too far? (I know an early DAS touched on this) - Is this amount of logic ok in a view, if it's tested? (Views are essentially methods, right?) Of course, those kinds of questions make a 2 hour feature take a day... -
jonsmock revised this gist
Dec 22, 2011 . 6 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes.File renamed without changes.File renamed without changes.File renamed without changes.File renamed without changes. -
jonsmock revised this gist
Dec 22, 2011 . 7 changed files with 81 additions and 93 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 @@ -0,0 +1,5 @@ class RosterController < ApplicationController def index @roster = Roster.new(Employees.morning_shift) 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 charactersOriginal file line number Diff line number Diff line change @@ -1,93 +0,0 @@ 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,18 @@ # This example is not my real app, but it's modeled pretty closely to it. # My mom schedules a couple hundred employees at a local warehouse. In their # system, a worker can earn "points" for being late or missing shifts. Here # we have a sort of summary screen for my mom, who may need to follow up with # new employees or discipline employees with concerning levels of points. # Questions that arise as I code something like this: # - Which objects deserve presenters? # - Should I allow HTML in my presenters? # - Do partials help or do they actually hide complexity that should be # eliminated? # - Do I sometimes take the Law of Demeter too far? (I know an early DAS touched # on this) # - Is this amount of logic ok in a view, if it's tested? (Views are essentially # methods, right?) # Of course, those kinds of questions make a 2 hour feature take a day... 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,7 @@ module EmployeeStatus def recently_hired?; end def scheduled?; end def points_are_concerning?; end def deliquent_points; 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ class Employee < ActiveRecord::Base include EmployeeStatus def hired_on; end def received_employee_handbook?; end def scheduled_by; end def last_worked_on; 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ class Roster attr_accessible :employees def initialize(employees) @employees = employees 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ <ul> <% @roster.employees.each do |employee| %> <li> <h2><%= employee.full_name %></h2> <% if employee.recently_hired? %> <p>This employee was hired on <%= employee.hired_on %> <% if employee.scheduled? %> and was scheduled by <%= employee.scheduled_by %>!</p> <%= link_to 'View Shifts', employee_path(employee) %> <% else %> but still needs to be scheduled.</p> <%= link_to 'Schedule now', new_employee_shift_path(employee) %> <% end %> <% unless employee.received_employee_handbook? %> <p>Make sure they have a copy of the handbook!</p> <% end %> <% elsif employee.points_are_concerning? %> <p>This employee needs disciplinary action. They currently have <%= pluralize(employee.deliquent_points, 'point') %>.</p> <p>Please consult management before scheduling more shifts.</p> <% else %> <% if employee.scheduled? %> This employee is in good standing. They last worked on <%= employee.last_worked_on %>. <%= link_to 'View Shifts', employee_path(employee) %> <% else %> <p>This employee has never been scheduled.</p> <%= link_to 'Schedule now', new_employee_shift_path(employee) %> <% end %> <% end %> </li> <% end %> </ul> -
jonsmock created this gist
Dec 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,93 @@ # This example is not my real app, but it's modeled pretty closely to it. # My mom schedules a couple hundred employees at a local warehouse. In their # system, a worker can earn "points" for being late or missing shifts. Here # we have a sort of summary screen for my mom, who may need to follow up with # new employees or discipline employees with concerning levels of points. # Questions that arise as I code something like this: # - Which objects deserve presenters? # - Should I allow HTML in my presenters? # - Do partials help or do they actually hide complexity that should be # eliminated? # - Do I sometimes take the Law of Demeter too far? (I know an early DAS touched # on this) # - Is this amount of logic ok in a view, if it's tested? (Views are essentially # methods, right?) # Of course, those kinds of questions make a 2 hour feature take a day... # ...On to the example! # --- class Employee < ActiveRecord::Base include EmployeeStatus def hired_on; end def received_employee_handbook?; end def scheduled_by; end def last_worked_on; end end module EmployeeStatus def recently_hired?; end def scheduled?; end def points_are_concerning?; end def deliquent_points; end end class Roster attr_accessible :employees def initialize(employees) @employees = employees end end class RosterController < ApplicationController def index @roster = Roster.new(Employees.morning_shift) end end # # and finally, the nasty, nasty view - barf # <ul> <% @roster.employees.each do |employee| %> <li> <h2><%= employee.full_name %></h2> <% if employee.recently_hired? %> <p>This employee was hired on <%= employee.hired_on %> <% if employee.scheduled? %> and was scheduled by <%= employee.scheduled_by %>!</p> <%= link_to 'View Shifts', employee_path(employee) %> <% else %> but still needs to be scheduled.</p> <%= link_to 'Schedule now', new_employee_shift_path(employee) %> <% end %> <% unless employee.received_employee_handbook? %> <p>Make sure they have a copy of the handbook!</p> <% end %> <% elsif employee.points_are_concerning? %> <p>This employee needs disciplinary action. They currently have <%= pluralize(employee.deliquent_points, 'point') %>.</p> <p>Please consult management before scheduling more shifts.</p> <% else %> <% if employee.scheduled? %> This employee is in good standing. They last worked on <%= employee.last_worked_on %>. <%= link_to 'View Shifts', employee_path(employee) %> <% else %> <p>This employee has never been scheduled.</p> <%= link_to 'Schedule now', new_employee_shift_path(employee) %> <% end %> <% end %> </li> <% end %> </ul>