Skip to content

Instantly share code, notes, and snippets.

View slawosz's full-sized avatar

Sławosz Sławiński slawosz

View GitHub Profile
@slawosz
slawosz / devise-with-mongoid-configuration.rb
Created May 20, 2010 07:13
template files for rails3 application with mongoid and devise with simple css, usage: rails app_name -m http://gist.github.com/raw/407296/edge-mongoid-devise.rb
puts "Setting up Devise"
# Install devise
run "rails generate devise_install"
gsub_file "config/initializers/devise.rb", "require 'devise/orm/active_record'", "require 'devise/orm/mongoid'"
# Install mongoid
# Disable activerecord framework
>> a = ActionController::Base.instance_method(:render)
=> #<UnboundMethod: ActionController::Base#render>
>> b = ActionController::Base.instance_method(:render_with_amf)
=> #<UnboundMethod: ActionController::Base#render_with_amf>
>> a == b
=> true
alias_method :orig_render, :render
def render(*args, &block)
p args.inspect
orig_render(args.first, opt, block)
end
class SimpleFactoryBuilder
def self.build_factories( klass, field_for_factory_name, *excluded )
attributes = klass.new.attributes
excluded.each { |e| attributes.symbolize_keys!.delete(e.to_sym) }
klass.all.each do |row|
attributes_string = ""
attributes.each_key do |key|
attributes_string << factory_attribute_row(row, key)
end
factory = <<-STRING
From 930c2177ffa6b560c7718974f52be2b20f149dcb Mon Sep 17 00:00:00 2001
From: =?utf-8?q?S=C5=82awosz=20S=C5=82awi=C5=84ski?= <slawosz@slawosz-laptop.(none)>
Date: Wed, 9 Jun 2010 15:42:47 +0200
Subject: [PATCH] render signature compatible with rails
---
vendor/plugins/rubyamf/util/action_controller.rb | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/vendor/plugins/rubyamf/util/action_controller.rb b/vendor/plugins/rubyamf/util/action_controller.rb
require 'rubygems'
if RUBY_VERSION >= '1.9'
require 'time'
require 'date'
require 'active_support/time'
else
require 'active_support'
require 'active_support/core_ext'
end
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# don't put duplicate lines in the history. See bash(1) for more options
# don't overwrite GNU Midnight Commander's setting of `ignorespace'.
export HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups
== Installation
require 'dir_dsl'
== Usage
Directory 'foo' in current directory, with subdirectory 'bar' and file 'baz'
Dir 'foo' do
dir 'bar'
@slawosz
slawosz / super_in_ruby.rb
Created January 4, 2011 10:28
Chcecking hierarchy in ruby
module Foo
def foo
begin
super
p 'foo!'
rescue
p 'foo'
end
end
end
@slawosz
slawosz / module_instead_alias.rb
Created January 7, 2011 12:05
use module hierarchy!
# people write such a code
class Person
def say(word)
puts word
end
end
class Person
alias_method :old_say, :say