Skip to content

Instantly share code, notes, and snippets.

View brianknapp's full-sized avatar

Brian Knapp brianknapp

View GitHub Profile
@brianknapp
brianknapp / tweet contract thingy.rb
Created September 14, 2012 18:32
tweet pre-post condition contract
class Contract
@@disable_override = false
@@contracts = []
def self.method_added name
unless @@disable_override
@@contracts.each do |method|
if name == method.to_sym
method_alias = "#{method}_alias".to_sym
@brianknapp
brianknapp / gist:3756197
Created September 20, 2012 14:14
clean tweet gateway contract tests
require_relative '../../contracts/tweet_gateway_contract'
class TG < TweetGatewayContract
def save input
return input
end
end
class TGoutput < TweetGatewayContract
def save input
@brianknapp
brianknapp / gist:4150482
Created November 26, 2012 20:40
Self contained knockout error bubble with close button
<div class="alert error" data-bind="css: { hidden: !errorMessage() }">
<span data-bind="text: errorMessage"></span>
<button class="close" data-bind="click: function(data, event){ errorMessage(null); } ">&times;</button>
</div>
@brianknapp
brianknapp / example_action.yml
Created December 24, 2012 02:11
Example Obvious Descriptor
Action: ExampleAction
Description: should do something awesome
Code:
- c: validate input
- c: set default id and values for new Thing entity
- c: create/populate Thing object
requires: Thing.populate
- c: save thing to jack
requires: ThingJack.save, Thing.to_hash
- c: return the result
@brianknapp
brianknapp / sign_in_user.rb
Created February 5, 2013 18:38
This is a overly simplistic sign in user action that demonstrates roughly how a sign in might work in Obvious with users and user sessions
require_relative '../entities/user'
require_relative '../entities/user_session'
class SignInUser
def initialize user_jack, user_session_jack
@user_jack = user_jack
@user_session_jack = user_session_jack
end
@brianknapp
brianknapp / create_request.rb
Created February 12, 2013 01:44
This is sample code for a CreateRequest object. I don't know exactly what this is supposed to do, so I'm going to make this up as I go. Hopefully it is helpful to show multiple jacks on one action.
class CreateRequest
def initialize request_jack, notification_jack, payment_jack
@request_jack = request_jack
@notification_jack = notification_jack
@payment_jack = payment_jack
end
def execute input
unless input.has_shape? user_id: Fixnum, text: String, amount: Float, who_to_notify: Fixnum
@brianknapp
brianknapp / immutable_entity.rb
Last active December 15, 2015 07:09
Obvious immutable entity with validation
module Obvious
module EntityMixin
class << self
def included(base)
base.extend ClassMethods
end
end
@brianknapp
brianknapp / objective-ruby.rb
Last active December 16, 2015 02:29
Objective-Ruby? This is an attempt add type checking and more descriptive named parameters to ruby. This might make it in to Obvious at some point...
module ObjectiveRuby
class << self
def included(base)
base.extend ClassMethods
end
end
module ClassMethods
def obj method, input = {}, &block
@brianknapp
brianknapp / user.rb
Created April 12, 2013 14:03
Obvious User Entity
class User < Obvious::Entity
value :email, String
value :password, String
value :id, Fixnum
validation :check_email, Proc.new {
raise StandardError.new 'invalid email address' unless email =~ /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i
}
@brianknapp
brianknapp / page_should_contain.rb
Created April 16, 2013 18:29
Webrat page_should_contain matcher monkeypatch
# This is an alias method to give better language to the assert_contain matcher
module Webrat::Matchers
def page_should_contain content
assert_contain content
end
end