merged_default_scopes 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +3 -0
- data/History.markdown +6 -2
- data/LICENSE +1 -1
- data/README.markdown +50 -12
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/merged_default_scopes.rb +4 -0
- data/merged_default_scopes.gemspec +6 -4
- data/spec/db/schema.rb +7 -0
- data/spec/merged_default_scopes_spec.rb +14 -21
- data/spec/spec_helper.rb +12 -0
- metadata +6 -4
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/History.markdown
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
-
# Version 0.0.
|
1
|
+
# Version 0.0.3 / 2010-05-16
|
2
|
+
|
3
|
+
* add clear_default_scope
|
4
|
+
|
5
|
+
# Version 0.0.2 / 2010-05-12
|
2
6
|
|
3
7
|
* Now it actually works!
|
4
8
|
|
5
|
-
# Version 0.0.1 / 2010-05-
|
9
|
+
# Version 0.0.1 / 2010-05-11
|
6
10
|
|
7
11
|
* Initial cut
|
8
12
|
* Supports active_record-2.3.5 only
|
data/LICENSE
CHANGED
data/README.markdown
CHANGED
@@ -1,30 +1,68 @@
|
|
1
1
|
# merged\_default\_scopes
|
2
2
|
|
3
|
-
|
3
|
+
require 'merged_default_scopes'
|
4
|
+
|
5
|
+
module SomePlugin
|
4
6
|
def self.included(mod)
|
5
7
|
mod.default_scope :conditions => {:deleted_at => nil}
|
6
8
|
end
|
7
9
|
end
|
8
10
|
|
9
11
|
class SomeModel < ActiveRecord::Base
|
10
|
-
include
|
12
|
+
include SomePlugin
|
11
13
|
|
12
14
|
default_scope :order => :name
|
13
15
|
end
|
14
|
-
|
15
|
-
|
16
|
+
|
17
|
+
SomeModel.__send__(:scope, :find)
|
18
|
+
# => {:order => :name, :conditions => {:deleted_at => nil}}
|
16
19
|
#
|
17
20
|
# ... and all is right with the world
|
18
21
|
|
19
|
-
|
22
|
+
# clear\_default\_scope
|
23
|
+
|
24
|
+
require 'merged_default_scopes'
|
25
|
+
|
26
|
+
class SomeModel < ActiveRecord::Base
|
27
|
+
include SomePluginThatMightSetDefaultScope
|
28
|
+
include AnotherPluginThatMightSetDefaultScope
|
29
|
+
|
30
|
+
clear_default_scope
|
31
|
+
default_scope :order => :name
|
32
|
+
end
|
33
|
+
|
34
|
+
SomeModel.__send__(:scope, :find)
|
35
|
+
# => {:order => :name}
|
36
|
+
#
|
37
|
+
# ... and all is right with the world, assuming you want the old
|
38
|
+
# behaviour of default_scope, which is to overwrite previously set
|
39
|
+
# default scopes
|
40
|
+
|
41
|
+
## Motivation
|
42
|
+
|
43
|
+
Sometimes plugins use `default_scope` to do what they do. We need a means of adding to
|
44
|
+
the default scope without blowing it away.
|
45
|
+
|
46
|
+
This is going to be the behaviour of default_scope and clear_default_scope in
|
47
|
+
rails-3 (as of http://github.com/rails/rails/commit/35a114a8941cb22d29a536f1215a23a8cf7c4756),
|
48
|
+
so this gem serves as a back-port to rails-2.
|
49
|
+
|
50
|
+
## Install
|
51
|
+
|
52
|
+
$ gem install merged_default_scopes
|
53
|
+
|
54
|
+
## Contribute
|
20
55
|
|
21
|
-
* Fork the project.
|
22
|
-
* Make
|
23
|
-
*
|
24
|
-
*
|
25
|
-
|
26
|
-
|
56
|
+
* [Fork the project](http://github.com/dchelimsky/merged_default_scopes)
|
57
|
+
* Make the code better with a new feature, bug fix, or refactoring.
|
58
|
+
* New features and bug fixes should have specs.
|
59
|
+
* Send us a pull request.
|
60
|
+
|
61
|
+
## Learn more
|
62
|
+
|
63
|
+
* [code/docs](http://github.com/dchelimsky/merged_default_scopes)
|
64
|
+
* [issues](http://github.com/dchelimsky/merged_default_scopes/issues)
|
27
65
|
|
28
66
|
## Copyright
|
29
67
|
|
30
|
-
Copyright (c) 2010 David Chelimsky and
|
68
|
+
Copyright (c) 2010 David Chelimsky and Brian Tatnall. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ begin
|
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "merged_default_scopes"
|
8
8
|
gem.summary = %Q{the name says it all}
|
9
|
-
gem.description = %Q{modify behavior of default_scope
|
9
|
+
gem.description = %Q{modify behavior of ActiveRecord::Base::default_scope to merge rather than overwrite}
|
10
10
|
gem.email = "dchelimsky@gmail.com,btatnall@gmail.com"
|
11
11
|
gem.homepage = "http://github.com/dchelimsky/merged_default_scopes"
|
12
12
|
gem.authors = ["David Chelimsky", "Brian Tatnall"]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
@@ -5,12 +5,12 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{merged_default_scopes}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["David Chelimsky", "Brian Tatnall"]
|
12
|
-
s.date = %q{2010-05-
|
13
|
-
s.description = %q{modify behavior of default_scope
|
12
|
+
s.date = %q{2010-05-16}
|
13
|
+
s.description = %q{modify behavior of ActiveRecord::Base::default_scope to merge rather than overwrite}
|
14
14
|
s.email = %q{dchelimsky@gmail.com,btatnall@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
|
|
30
30
|
"autotest/discover.rb",
|
31
31
|
"lib/merged_default_scopes.rb",
|
32
32
|
"merged_default_scopes.gemspec",
|
33
|
+
"spec/db/schema.rb",
|
33
34
|
"spec/merged_default_scopes_spec.rb",
|
34
35
|
"spec/spec_helper.rb"
|
35
36
|
]
|
@@ -39,7 +40,8 @@ Gem::Specification.new do |s|
|
|
39
40
|
s.rubygems_version = %q{1.3.6}
|
40
41
|
s.summary = %q{the name says it all}
|
41
42
|
s.test_files = [
|
42
|
-
"spec/
|
43
|
+
"spec/db/schema.rb",
|
44
|
+
"spec/merged_default_scopes_spec.rb",
|
43
45
|
"spec/spec_helper.rb"
|
44
46
|
]
|
45
47
|
|
data/spec/db/schema.rb
ADDED
@@ -1,33 +1,26 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
class SomeModel < ActiveRecord::Base
|
4
|
-
def initialize
|
5
|
-
@columns = []
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.columns
|
9
|
-
@columns ||= [];
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.column(name, sql_type = nil, default = nil, null = true)
|
13
|
-
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
|
14
|
-
end
|
15
|
-
|
16
|
-
column :deleted_at, :datetime
|
17
|
-
column :name, :string
|
18
|
-
end
|
3
|
+
class SomeModel < ActiveRecord::Base; end
|
19
4
|
|
20
5
|
describe MergedDefaultScopes do
|
6
|
+
after(:each) do
|
7
|
+
SomeModel.__send__ :clear_default_scope
|
8
|
+
end
|
21
9
|
describe "#default_scope" do
|
22
|
-
|
10
|
+
it "merges multiple calls" do
|
23
11
|
SomeModel.__send__ :default_scope, :order => :name
|
24
12
|
SomeModel.__send__ :default_scope, :conditions => {:deleted_at => nil}
|
25
|
-
end
|
26
|
-
|
27
|
-
it "merges multiple calls" do
|
28
13
|
SomeModel.__send__(:scope, :find).
|
29
14
|
should == {:order => :name, :conditions => {:deleted_at => nil}}
|
30
15
|
end
|
31
16
|
end
|
32
|
-
end
|
33
17
|
|
18
|
+
describe "#clear_default_scope" do
|
19
|
+
it "clears default scopes" do
|
20
|
+
SomeModel.__send__ :default_scope, :order => :name
|
21
|
+
SomeModel.__send__ :default_scope, :conditions => {:deleted_at => nil}
|
22
|
+
SomeModel.__send__ :clear_default_scope
|
23
|
+
SomeModel.__send__(:scope, :find).should be_nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,16 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
2
|
require 'merged_default_scopes'
|
3
3
|
require 'rspec'
|
4
|
+
require "sqlite3"
|
5
|
+
|
6
|
+
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
|
7
|
+
ActiveRecord::Base.establish_connection(
|
8
|
+
:adapter => "sqlite3",
|
9
|
+
:database => ":memory:"
|
10
|
+
)
|
11
|
+
ActiveRecord::Migration.verbose = false
|
12
|
+
load(File.dirname(__FILE__) + "/db/schema.rb")
|
13
|
+
|
14
|
+
class AuditableModel < ActiveRecord::Base; end
|
15
|
+
|
4
16
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- David Chelimsky
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-05-
|
18
|
+
date: 2010-05-16 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
version: 2.0.0.beta.8
|
35
35
|
type: :development
|
36
36
|
version_requirements: *id001
|
37
|
-
description: modify behavior of default_scope
|
37
|
+
description: modify behavior of ActiveRecord::Base::default_scope to merge rather than overwrite
|
38
38
|
email: dchelimsky@gmail.com,btatnall@gmail.com
|
39
39
|
executables: []
|
40
40
|
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- autotest/discover.rb
|
58
58
|
- lib/merged_default_scopes.rb
|
59
59
|
- merged_default_scopes.gemspec
|
60
|
+
- spec/db/schema.rb
|
60
61
|
- spec/merged_default_scopes_spec.rb
|
61
62
|
- spec/spec_helper.rb
|
62
63
|
has_rdoc: true
|
@@ -90,5 +91,6 @@ signing_key:
|
|
90
91
|
specification_version: 3
|
91
92
|
summary: the name says it all
|
92
93
|
test_files:
|
94
|
+
- spec/db/schema.rb
|
93
95
|
- spec/merged_default_scopes_spec.rb
|
94
96
|
- spec/spec_helper.rb
|