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 TranslationsMacro | |
def translates(*attr_names) | |
options = attr_names.extract_options! | |
setup_translations(options) unless translates? | |
add_translated_attributes(attr_names.map(&:to_sym) - translated_attribute_names) | |
end | |
def setup_translations(options) | |
include InstanceMethods | |
extend ClassMethods |
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
# Deep record dump | |
# | |
# Usage: | |
# dump = DeepRecordDump.new(order) | |
# | |
# 1) build sql dump file | |
# dump.write('/var/www/your_app/tmp/order_nnn.sql') | |
# 2) build shell commands to restore assets | |
# puts dump.shell_dump | |
# 3) restore `mysql db_name -e 'source /var/www/your_app/tmp/order_nnn.sql'` !!! NOT mysql db_name < dump.sql !!! |
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 ruby | |
dir = ARGV[0] | |
regexps = [ | |
{from: /(\s+)(.+?)\.should ==/, to: '\1expect(\2).to eq'}, | |
{from: /(\s+)(.+?)\.should =~ \[/, to: '\1expect(\2).to match_array ['}, | |
{from: 'be_true', to: 'be_truthy'}, | |
{from: 'be_false', to: 'be_falsey'}, | |
{from: /(\s+)(.+?)\.should(?:(_)?(not)?) be_(\w+)/, to: '\1expect(\2).\4\3to be_\5'}, | |
{from: /(\s+)(.+?)\.should(?:(_)?(not)?)_(\w+)/, to: '\1expect(\2).\4\3to \5'}, |
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 AdminAutocompleteApp | |
def self.call(env) | |
I18n.locale = :ru | |
params = Rack::Request.new(env).params | |
raw_klass = params['custom'].try(:fetch, 'class') || params['class'] | |
klass = Rack::Utils.unescape(raw_klass).safe_constantize | |
options = params.slice('with', 'with_all', 'without', 'page', 'per_page').symbolize_keys | |
options[:no_escape] = true |
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 'optparse' | |
require 'yaml' | |
require 'fileutils' | |
# === config/config.yml === | |
#dump: | |
# database: | |
# environments: |
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 ApplicationMailer < ActionMailer::Base | |
def self.deliver_mail(mail, &block) | |
begin | |
super(mail, &block) | |
rescue => e | |
begin | |
dir = Rails.root.join('data/exception_emails') | |
FileUtils.mkdir_p(dir) | |
path = File.join(dir, "#{Time.current.to_s(:path)}__#{mail.object_id}.eml") |