This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'zeus/rails' | |
class CucumberPlan < Zeus::Rails | |
def cucumber_environment | |
require 'cucumber/rspec/disable_option_parser' | |
require 'cucumber/cli/main' | |
@cucumber_runtime = Cucumber::Runtime.new | |
end | |
def cucumber(argv=ARGV) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Deciding how to handle a collection based on its size. | |
# | |
# Inspired by http://silkandspinach.net/2012/07/06/hexagonal-rails-hiding-the-finders/ | |
# | |
# See below for usage | |
module Demux | |
def demux(demux, outputs = nil, &block) | |
if outputs && block_given? | |
raise ArgumentError, "Pass either a block or an object, not both" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MyMixin | |
def say_hello | |
"hello!" | |
end | |
end | |
Object.new.extend(MyMixin).say_hello #=> "hello!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PersistentCollection | |
def initialize(klass) | |
@klass = klass | |
end | |
# ... | |
end | |
# This should be reusable | |
class ScopedCollection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Outcome | |
HANDLER = "if_" | |
HANDLER_RX = /^#{HANDLER}/ | |
QUERY_RX = /\?$/ | |
def self.new(result, *args, &b) | |
super.tap { |o| yield o if block_given? } | |
end | |
def initialize(result, *args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# admin/real_estate_companies.rb | |
ActiveAdmin.register RealEstateCompany do | |
form do |f| | |
f.inputs do | |
f.input :vendors, collection: Vendor.sorted_by_name | |
end | |
end | |
end | |
# models/vendor.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Assertions | |
def demand(&block) | |
block.call or raise ConditionFailed | |
end | |
def promise(&block) | |
tap { |o| yield o or raise ConditionFailed } | |
end | |
def refuse(&block) |
OlderNewer