I hereby claim:
- I am gareth on github.
- I am garethadams (https://keybase.io/garethadams) on keybase.
- I have a public key whose fingerprint is 6CA8 8151 9967 9822 D3E5 69D4 0E9F C2A0 95EC 3DDD
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
require 'logger' | |
# Adds configurable logger functionality to a class | |
# | |
# class Foo | |
# include Loggable | |
# | |
# def complicated_method | |
# logger.debug("Foo") { "Beginning long method" } | |
# sleep(2) |
<% clients = @clients.select { |c| c.clientID == 2 } %> | |
<%= clients.map(&:clientID) %> |
[:user, :crypted_password, :uid, :gid, :homedir, :mail_dir, :options, :quota].each do |attribute| | |
define_method attribute do | |
@attributes[attribute] | |
end | |
end |
Then /^I should see( only)? the following error messages?( in order)?:$/ do |only, ordered, table| | |
# Uses Capybara's `all` CSS selector to find error messages in Rails' default | |
# error messages output format | |
errors = all(:css, "#errorExplanation li").map { |error| [error.text] } | |
errors_expected = table.raw | |
errors_actual = only ? errors : (errors & table.raw) | |
unless ordered | |
# Cucumber cares about the order of tables, If we don't then we need to sort | |
# both sets of messages using the same criteria | |
errors_actual = errors_actual.sort |
require 'test/unit/assertions' | |
include Test::Unit::Assertions | |
assert_equal "1.9.2", RUBY_VERSION | |
# A Ruby meta-programming puzzle for polite programmers. | |
# This puzzle was created by Matt Wynne (@mattwynne) on 2011-04-10 inspired by Jim Weirich's | |
# talk at the Scottish Ruby Conference 2011. | |
# | |
# The challenge is: you have a class Foo which you want to monkey-patch, but politely. |
This snippet is something I put together to play around with the FestivalsLab API inside a Rails app I was building. I built it with Rails 3 on Ruby 1.9.2 but there's no reason it shouldn't work on older versions of either of those.
This could potentially be used as a bare Ruby library without Rails, but I am using a couple of useful features - Rack's query string parsing and some MIME type handling - that would have to be rewritten to do that. I'm using these features because I don't think that any URI string manipulation should happen outside of a URI library, your philosophy may be different ;)
This code should be considered a work in progress, there are no guarantees that it will work for you, or that it won't wipe your hard drive. But you can see the code, it's all pretty simple.
Installation
class Project < ActiveRecord::Base | |
has_many :goals | |
end | |
class Goal < ActiveRecord::Base | |
belongs_to :project | |
class << self | |
def setup *some_fields | |
new.tap do |goal| |
#!/usr/bin/env ruby | |
require 'logger' | |
$stdout.sync = true | |
$stdin.sync = true | |
path = "/usr/local/var/log/ejabberd/auth.log" | |
file = File.open(path, File::WRONLY | File::APPEND | File::CREAT) | |
file.sync = true | |
$logger = Logger.new(file) | |
$logger.level = Logger::DEBUG |
source :rubygems |