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
| def log(message) | |
| delayed_message = proc{"#{Time.now.strftime("%T.%L")} pid:#{Process.pid} cache_id:#{@cache_id} #{message}"} | |
| Rails.logger.error(" #{incr} #{delayed_message.()}") | |
| res = yield | |
| Rails.logger.error(" #{decr} #{delayed_message.()}") | |
| res | |
| end | |
| def incr | |
| @nesting ||= 0 |
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 'active_support/all' | |
| require 'timeout' | |
| class CacheMutex | |
| INTERVAL = 0.01 | |
| TIMEOUT = 20 | |
| def initialize(name) | |
| @name = name | |
| @have_lock = false |
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
| group :test do | |
| gem 'vcr' | |
| gem 'fakeweb' | |
| 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
| spec/cassettes* |
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
| describe "group", :vcr do | |
| ... | |
| end | |
| context "other group", :vcr do | |
| ... | |
| 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
| require 'vcr' | |
| ... | |
| VCR.configure do |c| | |
| c.cassette_library_dir = 'spec/cassettes' | |
| c.hook_into :fakeweb | |
| c.configure_rspec_metadata! | |
| end | |
| RSpec.configure do |config| | |
| ... |
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 User < ActiveRecord::Base | |
| STATUS = { :active => 1, :inactive => 2, :pending => 3, :announce => 4, :curator => 5 } | |
| STATUS.each do |k, v| | |
| define_singleton_method(k) do | |
| where(:status => v) | |
| 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
| class User < ActiveRecord::Base | |
| STATUS = { :active => 1, :inactive => 2, :pending => 3, :announce => 4, :curator => 5 } | |
| def self.active; where(:status => STATUS[:active]); end | |
| def self.inactive; where(:status => STATUS[:inactive]); end | |
| def self.pending; where(:status => STATUS[:pending]); end | |
| def self.announce; where(:status => STATUS[:announce]); 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 User < ActiveRecord::Base | |
| STATUS = { :active => 1, :inactive => 2, :pending => 3, :announce => 4, :curator => 5 } | |
| scope :active, where("status = #{STATUS[:active]}") | |
| scope :inactive, where("status = #{STATUS[:inactive]}") | |
| scope :pending, where("status = #{STATUS[:pending]}") | |
| scope :announce, where("status = #{STATUS[:announce]}") | |
| 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
| require 'rubygems' | |
| require 'fog' | |
| connection = Fog::Storage.new(:provider => 'AWS') | |
| directory = connection.directories.find{|dir| dir.key == ENV['BUCKET_KEY']} | |
| file = directory.files.last | |
| File.open ENV['BACKUP_FILE'], 'w' do |backup| | |
| backup << file.body | |
| end |