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 'rspec/core/rake_task' | |
@parallel_limit = 4 | |
files = Dir.glob("spec/**/*_spec.rb") | |
pids = [] | |
@parallel_limit.times do |i| | |
pids << fork do | |
# Run the tests |
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 PaperTrailClassWrapper < SimpleDelegator | |
def initialize | |
__set_obj__(PaperTrail::Version) | |
end | |
def some_fancy_scope | |
where(item_type: "FancyClass") | |
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
#!/usr/bin/env bash -e | |
clare_dir=~/workspace/clare_accounting | |
disperation_dir=~/workspace/disperation | |
[ -s "$HOME/.rvm/scripts/rvm" ] && . "$HOME/.rvm/scripts/rvm" | |
function move_to_clare() { | |
builtin cd $clare_dir | |
rvm use ruby-2.1.1@clare_accounting &> /dev/null |
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 MultiattributeParam #:nodoc: | |
attr_reader :type, :values | |
def initialize(type, name, params) | |
@type = type | |
@values = {} | |
params.each do |key, value| | |
regex = /#{name}\((\d+)i\)/.match(key.to_s) | |
next unless regex && regex.captures.present? | |
@values[regex.captures.first.to_i] = value |
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
# Say you have | |
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| | |
class_attr_index = html_tag.index 'class="' | |
if class_attr_index | |
html_tag.insert class_attr_index+7, 'error ' | |
else | |
html_tag.insert html_tag.index('>'), ' class="error"' | |
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
array = [{ foo: :bar}, 1] | |
array.insert(array.index { |el| el.is_a?(Hash) }, 2) | |
array # => [2, { foo: :bar}, 1] |
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
# Let's say we have | |
# original = [ | |
# {"id"=>3, "address"=>"something@something.com", "alerts"=>false}, | |
# {"id"=>4, "address"=>"something2@something2.com", "alerts"=>false} | |
# ] | |
# new = [{"id"=>3, "address"=>"CHANGED@something.com", "alerts"=>false}] | |
original.reduce([]) { |array, el| | |
array << new.find { |new_element| new_element["id"] == el["id"] } || el | |
} |
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 Post < ActiveRecord::Base | |
belongs_to :author | |
has_many :comments | |
scope :author, ->(name) { joins(:author).where(author: { name: name }) } | |
scope :comment, ->(text) { joins(:comments).merge(Comment.text_query(text)) } | |
scope :text, ->(text) { where("text ILIKE ?", "%#{text}%") } | |
end | |
{ author: "Jon", comment: "awesome", text: "Ruby" }.reduce(Post) { |query, (scope, args)| |
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 foo(one, two = one) | |
[one, two] | |
end | |
foo("1") | |
# => ["1", "1"] | |
foo("1", "2") | |
# => ["1", "2"] |
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 File.expand_path("../config/environment", __FILE__) | |
require 'rspec' | |
# Disable for all serializers (except ArraySerializer) | |
ActiveModel::Serializer.root = false | |
# | |
# # Disable for ArraySerializer | |
ActiveModel::ArraySerializer.root = false | |
class AMSEnvelope |