Skip to content

Instantly share code, notes, and snippets.

class ProcMatcher
attr_accessor :proc, :calls, :args
def initialize(proc)
@proc = proc
@calls = []
@args = []
end
def parse
@calls = []
class Stream
include Enumerable
attr_reader :succ, :value
def initialize(value, &block)
@value, @succ = value, block
end
class LazEvalProxy
alias_method :proxy_respond_to?, :respond_to?
alias_method :proxy_extend, :extend
instance_methods.each { |m| undef_method m unless m =~ /(^__|^proxy_)/ }
attr_accessor :proxy_block, :proxy_object
def initialize(object, block)
@proxy_object, @proxy_block = object, block
end
require 'yaml'
# yaml-able proc
# write the proc as a string or a block that returns a string
# no bindings!
class Sproc
def initialize *args, &block
@proc_string = block_given? ? block.call.to_s : args.first.to_s
end
# Sometimes tests just keep rolling on when you would really like
# them to die so you can inspect the database without teardown
# or the next setup
def test_something
x_it = proc{ puts "This test failed!"; Kernel.exit(1) }
class << x_it
def to_s; call; end
alias inspect to_s
end
##
# Include this in your app as config/initializers/identity_map.rb
# But don't really, this is untested and not used in any production code.
#
# It is a partial implementation of Martin Fowler's IdentityMap.
# http://martinfowler.com/eaaCatalog/identityMap.html
#
# Combined with QueryCache it is a complete implementation ( almost ).
#
module IdentityMap
/*
* Extend the Event Object
*
* ready_dom: add functions to run on DOMContentLoaded
*
* ready_ajax: add functions to run after Ajax onComplete responses
*
* ready: add functions to run on both ready_dom & ready_ajax. These should
* be constructed so that running more than once will not have any
* side-effects.
##
# Like ck_fu ( http://github.com/r38y/ck_fu ) but not
# I really like ck_fu. But I am not fond of adding tests, rake tasks, and a whole plugin folder for
# one method, two helper methods and some css. I also made it safe for Rails 1.2.6.
#
# in app/helpers/application_helper.rb
def environment_div(options={})
return '' if (options.has_key?(:if) ? !options[:if] : RAILS_ENV.to_s == 'production' )
separator = options[:separator] || "|"
text = [content_tag(:strong, RAILS_ENV.to_s.titlecase)]
ActionController::Routing::RouteSet::Mapper
class ActionController::Routing::RouteSet::Mapper
def initialize(set)
@set = set
end
# Create an unnamed route with the provided +path+ and +options+. See
# SomeHelpfulUrl for an introduction to routes.
def connect(path, options = {})
puts "map.connect #{path}, #{options.inspect[1..-2]}"
module UpdatedAtLocking
def self.included(base)
base.alias_method_chain :update, :stale_object_detection
base.class_inheritable_accessor :updated_at_locking_enabled, :instance_writer => false
base.updated_at_locking_enabled = true
end
def updated_at_locking_enabled?
self.updated_at_locking_enabled == true