Skip to content

Instantly share code, notes, and snippets.

Avatar

Mike Kelly mikekelly

View GitHub Profile
View hactor_example.rb
require 'hactor'
class HomeActor
include Hactor::Actor
def on_200(response)
response.follow 'ht:users', actor: UserListActor.new
end
end
View thing.json
{
"_links": {
"self": {
"href": "/product/987"
},
"manufacturer": {
"href": "/manufacturer/328764",
"title": "Manufacturer Inc."
}
},
View halo_json_request.json
{
"_links": {
"self": { "href": "/foo" },
},
"_controls": {
"attack": {
"target": "/attacks",
"method": "POST",
"headers": {
"Content-Type": "application/json"
@mikekelly
mikekelly / rspec_stub_chain_if_spec.rb
Created Sep 27, 2012 — forked from deepak/rspec_stub_chain_if_spec.rb
mocking stub chains with an assertion if the final call is made
View rspec_stub_chain_if_spec.rb
require 'rspec'
class DevOps
attr_reader :monitor
def initialize(arguments)
@monitor = arguments.fetch(:monitor) { Monitor.new }
end
def check
View 0_widgets_example.rb
require_relative 'deferrable'
require_relative 'slime'
class WidgetsController
include ControllerSlime
def create
creator = WidgetCreator.new(attributes: params[:widget])
creator.done do |widget|
View example.hal.html
<!doctype html>
<head>
<title>An example tweet</title>
</head>
<body xmlns:ht="http://haltalk.herokuapp.com/rels/">
<form class="properties" action="" method="POST">
<input type="hidden" name="_method" value="PUT" />
<input name="content" value="Justin Bieber is grate!111" />
<input name="created_at" value="2012-07-07T22:35:33+00:00" />
<button>Update</button>
@mikekelly
mikekelly / sketch.rb
Created Jul 4, 2012 — forked from mattwynne/sketch.rb
sketch for Matt Wynne
View sketch.rb
class Organization
def to_param
"42"
end
def saved?
rand > 0.5
end
end
@mikekelly
mikekelly / Backbone-HAL.js.coffee
Created May 28, 2012
Two small components for making Backbone play nicely with application/hal+json
View Backbone-HAL.js.coffee
window.HAL = {}
class HAL.Model extends Backbone.Model
constructor: (attrs) ->
super @parse(_.clone attrs)
parse: (attrs = {}) ->
@links = attrs._links || {}
delete attrs._links
@embedded = attrs._embedded || {}
View part1.md

Inheritance is a key concept in most object-oriented languages, but applying it skillfully can be challenging in practice. Back in 1989, M. Sakkinen wrote a paper called Disciplined inheritance that addresses these problems and offers some useful criteria for working around them. Despite being more than two decades old, this paper is extremely relevant to the modern Ruby programmer.

Sakkinen's central point seems to be that most traditional uses of inheritance lead to poor encapsulation, bloated object contracts, and accidental namespace collisions. He provides two patterns for disciplined inheritance and suggests that by normalizing the way that we model things, we can apply these two patterns to a very wide range of scenarios. He goes on to show that code that conforms to these design rules can easily be modeled as ordinary object composition, exposing a solid alternative to tradi

View order.hal.json
{
"_links": {
"self": { "href": "/orders/123" },
"shipment-type": { "href": "http://api.company.com/logistics/shipmenttypes/2" },
"warehouse": { "href": "http://api.company.com/logistics/warehouses/7449?Country=Australia" },
"products": [{
"href": "http://api.company.com/master/products/87",
"title": "Shirt"
},{
"href": "http://api.company.com/master/products/122",