Skip to content

Instantly share code, notes, and snippets.

@jmondo
jmondo / simple_delegator_example.rb
Last active December 26, 2015 16:09
simple delegator example from sfrails oct 2013
# it's all part of ruby!
require 'ostruct'
require 'delegate'
require 'forwardable'
require 'minitest/autorun' # can run rspec style tests with this, part of ruby
# ---------------------------------------------------------------------------------------------------------
# the classes
# using simple delegator with the country object /after/ this app has been made with bad dependency mgmt.
# we swap the country string 'FIN' out for a country object with Country.new('FIN')
@maxim
maxim / rails_load_path_tips.md
Last active April 13, 2023 13:28
How to use rails load paths, app, and lib directories.

In Rails 3

NOTE: This post now lives (and kept up to date) on my blog: http://hakunin.com/rails3-load-paths

If you add a dir directly under app/

Do nothing. All files in this dir are eager loaded in production and lazy loaded in development by default.

If you add a dir under app/something/

PageObject + SimpleDelegator = Awesome Capybara Helpers

I've always liked using the Page Object pattern to write concise, namespaced, and composeable capybara helpers:

When /^I register as a new user$/ do
  NewUserPage.new(self).tap do |page|
    page.visit!
    page.form.fill

page.form.submit!

@eclosson
eclosson / pdf_merger.rb
Created January 11, 2013 18:29
Merging PDFs with Prawn
class PdfMerger
def merge(pdf_paths, destination)
first_pdf_path = pdf_paths.delete_at(0)
Prawn::Document.generate(destination, :template => first_pdf_path) do |pdf|
pdf_paths.each do |pdf_path|
pdf.go_to_page(pdf.page_count)
alias pclean="([ -f Makefile ] || perl Makefile.PL); make realclean && rm -f MANIFEST"
alias pinst="perl Makefile.PL INSTALLDIRS=vendor && make && make install && pclean"
alias pprepare="rm -rf inc MANIFEST && perl Makefile.PL && make manifest && perl Makefile.PL && make"
alias pdist="pprepare && make dist"
alias pupload="pprepare && make upload"