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 self.decode_content(c) | |
if c.header_str.match(/Content-Encoding: gzip/) | |
begin | |
gz = Zlib::GzipReader.new(StringIO.new(c.body_str)) | |
xml = gz.read | |
gz.close | |
rescue Zlib::GzipFile::Error | |
xml = c.body_str | |
end | |
elsif c.header_str.match(/Content-Encoding: deflate/) |
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 Trade | |
def users_with_destroyed | |
User.find_with_destroyed(:all, :conditions => {:id => self.user_id}) | |
end | |
def user_with_destroyed | |
User.find_with_destroyed(self.user_id) | |
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
require 'rubygems' | |
gem 'activerecord', '=2.3.2' | |
require 'activerecord' | |
load 'active_record/associations.rb' | |
load 'active_record/associations/has_many_through_association.rb' | |
ActiveRecord::Associations::HasManyThroughAssociation | |
class SomeClass < ActiveRecord::Associations::HasManyThroughAssociation | |
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
# thanks to @judofyr for explaining this to me like thus: | |
# when ruby sees "bar =" (even thought it's not eval'd) it creates a local variable and assigns it to nil. | |
# so the first "bar" is a method call, while the second is a local variable. it should work if you replace | |
# it with "self.bar". | |
class Foo | |
attr_accessor :bar, :id | |
def initialize id | |
@id = id |
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
diff --git a/lib/is_paranoid.rb b/lib/is_paranoid.rb | |
index 3c11248..c74adf1 100644 | |
--- a/lib/is_paranoid.rb | |
+++ b/lib/is_paranoid.rb | |
@@ -30,21 +30,33 @@ module IsParanoid | |
# NOTE: is_paranoid declaration must follow assocation declarations. | |
[:has_many, :has_one].each do |macro| | |
self.reflect_on_all_associations(macro).each do |assoc| | |
- if (a = assoc.klass.reflect_on_all_associations(:belongs_to).detect{ |a| a.class_name == self.class_name }) | |
- assoc.klass.send( |
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
diff --git a/lib/is_paranoid.rb b/lib/is_paranoid.rb | |
index cad76db..26624e0 100644 | |
--- a/lib/is_paranoid.rb | |
+++ b/lib/is_paranoid.rb | |
@@ -38,13 +38,22 @@ module IsParanoid | |
# Use update_all with an exclusive scope to restore undo the soft-delete. | |
# This bypasses update-related callbacks. | |
# | |
- # By default, restores cascade through associations that are | |
+ # By default, restores cascade through associations that are belongs_to |
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
>> project = Project.first | |
=> #<Project id: 1, name: "some project", created_at: "2009-05-16 16:37:41", updated_at: "2009-05-16 16:37:41"> | |
>> project.tasks | |
=> [] | |
>> project.tasks_attributes = [{:name => 'something'}] | |
=> [{:name=>"something"}] | |
>> project.save | |
=> true | |
>> project.tasks | |
=> [#<Task id: 3, name: "something", project_id: 1, deleted_at: nil, created_at: "2009-05-16 16:49:11", updated_at: "2009-05-16 16:49:11">] |
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
# I'm interested in improvements or variations on doing this in rspec | |
# assuming we have an instance of ActiveSupport::Cache::MemCacheStore | |
# as the constant Mem and we want to check to see if a method changes | |
# the value for a particular key | |
# this comes into play in the first spec below... | |
class MemcachedValueFor | |
def self.method_missing name, *args | |
Mem.fetch(name) |
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 ActiveRecord::Base | |
def self.find_values opts | |
sql = self.send(:construct_finder_sql, opts) | |
self.connection.select_values(sql) | |
end | |
end | |
>> Tagging.find_values(:select => :taggable_id, :limit => 30, :order => 'tagged_at asc') | |
=> ["1", "3", "6", "6", "6", "10", "10", "10", "11", "11", "11", "10", "10", "10", "10", "10", "13", "13", "13", "13", "13", "13", "15", "15", "15", "15", "15", "15", "15", "15"] |
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 data | |
data = { | |
:success => true, | |
:site => Site.find(params[:id]).site | |
} | |
render :json => data.to_json | |
# Returns { | |
# 'success': true, | |
# 'site': { | |
# 'site': { |