This file contains hidden or 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
" Vim color scheme based on http://github.com/jpo/vim-railscasts-theme | |
" | |
" Name: mikekreeki.vim | |
" Maintainer: Michal Krejčí | |
" License: MIT | |
set background=dark | |
hi clear | |
if exists("syntax_on") | |
syntax reset |
This file contains hidden or 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
{ | |
address: { | |
location1: 'Some location' | |
}, | |
land_line_phone: '333333333', | |
monthly_income: '450' | |
} |
This file contains hidden or 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 Client | |
belongs_to :country, counter_cache: true | |
def country_code=(country_code) | |
self.country = Country.by_code country_code | |
end | |
end |
This file contains hidden or 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 RSpec | |
module Macros | |
def action(&block) | |
before do |example| | |
if example.metadata.fetch(:action, true) | |
instance_eval(&block) | |
end | |
end | |
end | |
end |
This file contains hidden or 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 ActiveInteraction | |
class ObjectFilter < Filter | |
register :object | |
def cast(value) | |
@klass ||= klass | |
if matches?(value) | |
value | |
else |
This file contains hidden or 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 Foo < ActiveInteraction::Base | |
string :bar | |
# additional validations | |
# validates :bar, ... | |
def execute | |
unless do_something | |
errors.add :bar, 'is not cool' | |
end |
This file contains hidden or 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 EmailListener | |
def user_created(user) | |
UserMailer.welcome_email(user).deliver | |
end | |
end |
This file contains hidden or 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 PostsController < ApplicationController | |
respond_to :json # default to Active Model Serializers | |
def index | |
respond_with Post.all | |
end | |
def show | |
respond_with Post.find(params[:id]) | |
end |
This file contains hidden or 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 Object | |
alias :old_tap :tap | |
def tap(&block) | |
old_tap do | |
if block.arity == 0 | |
instance_eval &block | |
else | |
block.(self) |
This file contains hidden or 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 'nokogiri' | |
require 'active_support' | |
require 'benchmark' | |
# equal to... | |
list = ['nokogiri', 'active_support', 'benchmark'] | |
## never use `for` cycle (unless you know exactly why), it's considered a bad practice, | |
## you save one method call since `for` calls `each` method internally anyway |