Skip to content

Instantly share code, notes, and snippets.

View JAMSUPREME's full-sized avatar

JUSTIN SPENCER JAMSUPREME

View GitHub Profile
@JAMSUPREME
JAMSUPREME / 1_isolated_command.rb
Last active July 22, 2016 17:13
Command examples
# Common "result" returned by commands
class Result
attr_accessor :successful, :value, :msg
def successful?
@successful
end
def fail(msg)
@successful = false
@msg = msg
@JAMSUPREME
JAMSUPREME / 1_light_controller.rb
Created July 22, 2016 15:30
Introducing improvements
# Introducing Commands
# The controller is still bloated, but we'll solve that problem later
# Here we pull all of the "business logic" into useful abstractions so the controller is easy to read and maintain
class Admin::AdminController < ApplicationController
before_action :redirect_unless_admin
def index
render 'index'
end
@JAMSUPREME
JAMSUPREME / 1_big_controller.rb
Last active July 19, 2016 22:27
All the bad things
# This is an example of a controller that is doing too many things.
# It has a lot of code, and as new features get added this controller continues to bloat
class Admin::AdminController < ApplicationController
include ApprovalConcern
before_action :redirect_unless_admin
def index
render 'index'
end