Skip to content

Instantly share code, notes, and snippets.

@jonsmock
Created December 22, 2011 00:57
Show Gist options
  • Save jonsmock/1508427 to your computer and use it in GitHub Desktop.
Save jonsmock/1508427 to your computer and use it in GitHub Desktop.

Revisions

  1. jonsmock revised this gist Dec 22, 2011. 1 changed file with 0 additions and 3 deletions.
    3 changes: 0 additions & 3 deletions 0_the_explanation.txt
    Original 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
    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?)

  2. jonsmock revised this gist Dec 22, 2011. 1 changed file with 15 additions and 15 deletions.
    30 changes: 15 additions & 15 deletions 0_the_explanation.txt
    Original 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.
    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.
    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?)
    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...
    Of course, those kinds of questions make a 2 hour feature take a day...
  3. jonsmock revised this gist Dec 22, 2011. 6 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
  4. jonsmock revised this gist Dec 22, 2011. 7 changed files with 81 additions and 93 deletions.
    5 changes: 5 additions & 0 deletions the_controller.rb
    Original 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
    93 changes: 0 additions & 93 deletions the_example.rb
    Original file line number Diff line number Diff line change
    @@ -1,93 +0,0 @@
    # 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>
    18 changes: 18 additions & 0 deletions the_explanation.txt
    Original 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...
    7 changes: 7 additions & 0 deletions the_mixin.rb
    Original 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
    8 changes: 8 additions & 0 deletions the_model.rb
    Original 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
    7 changes: 7 additions & 0 deletions the_supporting_class.rb
    Original 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
    36 changes: 36 additions & 0 deletions the_view.html.erb
    Original 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>
  5. jonsmock created this gist Dec 22, 2011.
    93 changes: 93 additions & 0 deletions the_example.rb
    Original 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>