Skip to content

Instantly share code, notes, and snippets.

View mikekelly's full-sized avatar

Mike Kelly mikekelly

View GitHub Profile
@mikekelly
mikekelly / example.rb
Last active August 29, 2015 13:57
Greppable, prefixed delegation
# un-greppable delegate API
class Foo
delegate :qux, to: :bar, prefix: true
end
# possible fixes to the API to make it greppable
class Foo
delegate :bar_qux, to: :bar, prefixed: true
def create
card = current_user.credit_cards.create(card_params)
if card.persisted?
render :success
else
render :failure
end
end
{
"links":{
"self":"/orders",
"link-docs":[
{
"name":"v1",
"href":"http://api.example.com/docs/v1/{link}",
"templated":true
}
],
dir structure:
/lib/
/tmp/
/views/
/public/
/config.ru
/blog.rb
--
/*
I want to be able to build a DSL for node.js so that I can define app routes for an HTTP interface like this:
*/
{
"/blog" : {
GET: function(request) {
// List blog posts
},
#(entry point)
> GET /
< 200 OK
< Link: </lists/some-list>; rel="http://example.com/rels/list",
< </foobars/another-list>; rel="http://example.com/rels/list"
< {...}
<html>
<head>
(GET /list)
<link rel="self" href="/list">
<link rel="description" href="/list/description" />
<link rel="search" href="/list/search/{search_term}" />
<created_at>2010-01-16</created_at>
<updated_at>2010-02-21</updated_at>
<summary>An example list</summary>
<link rel="owner" href="/people/mike">
<name>Mike</name>
# Critical default settings:
disable_system_gems
disable_rubygems
bundle_path '.gems/bundler_gems'
# List gems to bundle here:
gem 'rails_dm_datastore'
gem 'rails', "2.3.5"
# Needed for Devise-Plugin
// (/app/resources/useraccount.js)
Resource({
respond_to: ["html", "xml", "json"],
http: {
GET: function() {
user = User.find(params.user);
respond_with(user);
},
PUT: function() {
<resource rel="self" href="/list">
<resource rel="description" href="/list/description" />
<resource rel="search" href="/list/search/{search_term}" />
<created_at>2010-01-16</created_at>
<updated_at>2010-02-21</updated_at>
<summary>An example list</summary>
<resource rel="owner" href="/people/mike">
<name>Mike</name>
<age>36</age>
</resource>