Slide 1

Slide 1 text

originate.com @brianvhughes Brian V. Hughes No Hexagons Required Separating Your Application from Rails

Slide 2

Slide 2 text

originate.com @brianvhughes Brian V. Hughes Why separate?

Slide 3

Slide 3 text

originate.com @brianvhughes Brian V. Hughes Why separate? Rails MVC encourages tight coupling Tight coupling inhibits long-term maintenance Tight coupling inhibits efficient TDD “Standard” Rails Controllers obliterate SRP

Slide 4

Slide 4 text

originate.com @brianvhughes Brian V. Hughes “Standard” Controller Responsibilities Receive HTTP request Authentication Authorization Parameter handling Coordinate models/ associations Control Persistence Perform business logic Call external APIs Render response data Return HTTP response

Slide 5

Slide 5 text

originate.com @brianvhughes Brian V. Hughes “Standard” Controller Responsibilities Receive HTTP request Authentication Authorization Parameter handling Coordinate models/ associations Control Persistence Perform business logic Call external APIs Render response data Return HTTP response

Slide 6

Slide 6 text

originate.com @brianvhughes Brian V. Hughes “Reduced” Controller Responsibilities Receive HTTP request Authentication Tell Application to perform work Render response data Return HTTP response

Slide 7

Slide 7 text

originate.com @brianvhughes Brian V. Hughes What does a “separated” application look like?

Slide 8

Slide 8 text

originate.com @brianvhughes Brian V. Hughes Entities and Interactors

Slide 9

Slide 9 text

originate.com @brianvhughes Brian V. Hughes Entities and Interactors Architecture, the Lost Years, Bob Martin, Ruby Midwest ‘11 https:/ /www.youtube.com/watch?v=WpkDN78P884

Slide 10

Slide 10 text

originate.com @brianvhughes Brian V. Hughes Functional Core, Imperative Shell

Slide 11

Slide 11 text

originate.com @brianvhughes Brian V. Hughes Functional Core, Imperative Shell Boundaries, Gary Bernhardt, RubyConf ‘12 https:/ /www.youtube.com/watch?v=yTkzNHF6rMs

Slide 12

Slide 12 text

originate.com @brianvhughes Brian V. Hughes Hexagonal Architecture

Slide 13

Slide 13 text

originate.com @brianvhughes Brian V. Hughes Hexagonal Architecture Presented by Matt Wynn at GORUCO ’12 https:/ /www.youtube.com/watch?v=CGN4RFkhH2M

Slide 14

Slide 14 text

originate.com @brianvhughes Brian V. Hughes Response State

Slide 15

Slide 15 text

originate.com @brianvhughes Brian V. Hughes Response State Presented by Brian V. Hughes, LVRUG 12/10/14 C V M

Slide 16

Slide 16 text

originate.com @brianvhughes Brian V. Hughes Response State C V M

Slide 17

Slide 17 text

originate.com @brianvhughes Brian V. Hughes Response State C V M

Slide 18

Slide 18 text

originate.com @brianvhughes Brian V. Hughes Response State C V M

Slide 19

Slide 19 text

originate.com @brianvhughes Brian V. Hughes Response State A new interface in controller actions, aka. Response State Pattern Response State service classes, that provide the new controller interface Response Object instances, passed from the service class, to the controller. Drives the pattern.

Slide 20

Slide 20 text

originate.com @brianvhughes Brian V. Hughes Response State Replace the body of a controller action with a call to a Response State service class. The class “responds”, via yield, with an object representing the new app state Action doesn’t inspect response object, but sends directed calls, to named states. Only 1 state can be active; that’s the path the controller action follows. The so-called “Design Pattern”

Slide 21

Slide 21 text

originate.com @brianvhughes Brian V. Hughes Response State Response State service class exposes only a :call method, as its public API. Ideally, that :call method returns nil, in the process of yielding a Response Object Service class responsible for defining the allowed states of the Response Object. Handles all high-level application logic, delegates to services and models. The Service Class

Slide 22

Slide 22 text

originate.com @brianvhughes Brian V. Hughes Response State Response Object always instantiated with 3 parameters: :state, :message, :context. The value of :state determines which methods Response Object responds to. When called with the current :state method value, it yields, otherwise returns nil. :message and :context can both be nil. The Response Object

Slide 23

Slide 23 text

originate.com @brianvhughes Brian V. Hughes Response State Presented by Brian V. Hughes, Originate ‘14 Ruby Gem developed by Alex Peachey https:/ /github.com/Originate/response_state