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
set nocompatible " be iMproved, required | |
filetype off " required | |
" set the runtime path to include Vundle and initialize | |
set rtp+=~/.vim/bundle/Vundle.vim | |
call vundle#begin() | |
" alternatively, pass a path where Vundle should install plugins | |
"call vundle#begin('~/some/path/here') | |
" let Vundle manage Vundle, required |
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
#!/usr/bin/ruby | |
require 'find' | |
require 'fileutils' | |
if ARGV.empty? | |
puts "passe o caminho para o projeto, sua mula!" | |
exit(1) | |
end | |
Find.find(ARGV[0]) do |f| |
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
attr_names.each do |attr_name| | |
attr_name = attr_name.to_s | |
class_eval("def #{attr_name}; read_and_symbolize_attribute('#{attr_name}'); end") | |
class_eval("def #{attr_name}= (value); write_symbolized_attribute('#{attr_name}', value); end") | |
# Adicao de um novo metodo que retorna a respectiva string descritiva para cada symbol presente no hash passado | |
# para a opcao :in | |
# class User < ActiveRecord::Base | |
# symbolize :gender, :in => [:female, :male] | |
# symbolize :so, :in => { | |
# :windows => "Windows XP", |
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
def to_select_sym_tag(choices, options, html_options) | |
choices = symbolize_values(choices).sort {|a, b| a <=> b} | |
to_select_tag(choices, options.merge(:prompt => "Escolha..."), html_options) | |
end |
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
named_scope :a_receber, :conditions => {:pagar_receber => RECEBER} | |
named_scope :a_pagar, :conditions => {:pagar_receber => PAGAR} | |
named_scope :do_cliente, lambda {|cliente| {:conditions => ["cliente_id = ?", cliente.is_a?(Fixnum) ? cliente : cliente.id]}} | |
named_scope :da_escola, lambda {|escola| {:conditions => ["escola_id = ?", escola.is_a?(Fixnum) ? escola : escola.id]}} |
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
ActionView::Base.field_error_proc = Proc.new {|html_tag, instance| | |
if instance.error_message.kind_of?(Array) | |
%(#{html_tag}<span class='validation-error'> #{instance.error_message.join(', ')}</span>) | |
else | |
%(#{html_tag}<span class='validation-error'> #{instance.error_message}</span>) | |
end | |
} |
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 'cucumber/rake/task' | |
namespace :cucumber do | |
Cucumber::Rake::Task.new(:plain) do |t| | |
t.cucumber_opts = "--format pretty" | |
t.step_list = %w{features/support/env.rb features/support/plain.rb features/step_definitions} | |
t.feature_list = %w{features/plain} | |
end | |
task :plain => 'db:test:prepare' |
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
def extract_model_name(controller_class); controller_class.to_s.match(/(.+)Controller/)[1]; end | |
def model(controller_class); extract_model_name(controller_class).singularize.constantize; end | |
def symbol_for_model(controller_class, options = {}) | |
tablename = extract_model_name(controller_class).tableize | |
options[:pluralize] ? tablename.to_sym : tablename.singularize.to_sym | |
end | |
describe "an ordinary 'show' action", :shared => true do |
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 Gato < Animal; end | |
class Cachorro < Animal; end | |
describe Animal do | |
before(:each) do | |
@animal = Animal.new | |
end | |
it "ao criar um Animal, o contador dos filhoes deve permanecer 0" do | |
lambda { a = Animal.new }.should_not change(Gato, :total) | |
end |
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
# O problema é que você quer algo que foge do comoportamento esperado em um esquema orientado a objetos. | |
# Se cachorro herda de animal, então cachorro É um animal. Logo, quando cria-se um novo cachorro, a contagem de | |
# animais também deve aumentar. Para burlar esse comportamento fiz o esquema abaixo, usando metaprogramação. | |
class Animal | |
def initialize | |
increment_total | |
end | |
def self.total | |
@@total |
OlderNewer