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
module ParamsFor | |
def params_for(model, *attributes) | |
return if method_defined? "#{model}_params" | |
define_method "#{model}_params" do | |
params.require(model).permit attributes | |
end | |
end | |
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
# in lib/tasks/rspec.rake | |
# within namespace | |
namespace :spec do | |
desc "Run all specs with RCov" | |
RSpec::Core::RakeTask.new('rcov') do |t| | |
t.pattern = "./spec/**/*_spec.rb" | |
t.rcov = true | |
t.rcov_opts = ['-Ispec --exclude', 'rubygems/*,rcov,.gem/*,blueprints.rb,features/*'] | |
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 'open-magazine' # requirements | |
class Article | |
include Any::Aweseome::Module # includes and extensions | |
belongs_to :author # relations to other models | |
attr_accessor :title, :pages # attribute definitions | |
RESERVED_TITLES = ['Coding Ruby'] # constants... |
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
#table must be a two columned cucumber table | |
keys = table.rows_hash.keys.map { |key| key.parameterize("_") } | |
attributes = keys.zip(table.rows_hash.values).flatten | |
attributes = Hash[*attributes] |
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
# stick it in your ~/.pryrc | |
# use 'xsel' or 'xclip' if you're in a Linux environment | |
# | |
def _cp(obj = Readline::HISTORY.entries[-2], *options) | |
if obj.respond_to?(:join) && !options.include?(:a) | |
if options.include?(:s) | |
obj = obj.map { |element| ":#{element.to_s}" } | |
end | |
out = obj.join(", ") | |
elsif obj.respond_to?(:inspect) |
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 Article < ActiveRecord::Base | |
LOGFILE = File.join(RAILS_ROOT, '/log/', "article_#{RAILS_ENV}.log") | |
def validate | |
log "was validated!" | |
end | |
def log(*args) | |
args.size == 1 ? (message = args; severity = :info) : (severity, message = args) |