basic_named_scopes 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +2 -0
- data/Rakefile +2 -1
- data/VERSION +1 -1
- data/basic_named_scopes.gemspec +8 -5
- data/lib/basic_named_scopes.rb +8 -1
- data/spec/basic_named_scopes_spec.rb +6 -0
- metadata +13 -3
data/README.rdoc
CHANGED
@@ -14,6 +14,8 @@ You can now write:
|
|
14
14
|
All named scopes are called the same, except for +include+, which is now
|
15
15
|
called +with+, because +include+ is a reserved method.
|
16
16
|
|
17
|
+
Also, the scope +conditions+ is aliased as +where+, just as in ActiveRecord 3.
|
18
|
+
|
17
19
|
Reuse them by making class methods:
|
18
20
|
|
19
21
|
class Post < ActiveRecord::Base
|
data/Rakefile
CHANGED
@@ -11,7 +11,8 @@ begin
|
|
11
11
|
gem.homepage = "http://github.com/iain/basic_named_scopes"
|
12
12
|
gem.authors = ["Iain Hecker"]
|
13
13
|
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
-
gem.add_development_dependency "temping", ">= 1.
|
14
|
+
gem.add_development_dependency "temping", ">= 1.3.0"
|
15
|
+
gem.add_development_dependency "activerecord", "< 3.0.pre"
|
15
16
|
end
|
16
17
|
Jeweler::GemcutterTasks.new
|
17
18
|
rescue LoadError
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/basic_named_scopes.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{basic_named_scopes}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Iain Hecker"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-01-10}
|
13
13
|
s.description = %q{Make your queries prettier and more reusable by having a named scope for every find-parameter. As easy as Post.include(:author, :comments)}
|
14
14
|
s.email = %q{iain@iain.nl}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -43,14 +43,17 @@ Gem::Specification.new do |s|
|
|
43
43
|
|
44
44
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
45
45
|
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
46
|
-
s.add_development_dependency(%q<temping>, [">= 1.
|
46
|
+
s.add_development_dependency(%q<temping>, [">= 1.3.0"])
|
47
|
+
s.add_development_dependency(%q<activerecord>, ["< 3.0.pre"])
|
47
48
|
else
|
48
49
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
49
|
-
s.add_dependency(%q<temping>, [">= 1.
|
50
|
+
s.add_dependency(%q<temping>, [">= 1.3.0"])
|
51
|
+
s.add_dependency(%q<activerecord>, ["< 3.0.pre"])
|
50
52
|
end
|
51
53
|
else
|
52
54
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
53
|
-
s.add_dependency(%q<temping>, [">= 1.
|
55
|
+
s.add_dependency(%q<temping>, [">= 1.3.0"])
|
56
|
+
s.add_dependency(%q<activerecord>, ["< 3.0.pre"])
|
54
57
|
end
|
55
58
|
end
|
56
59
|
|
data/lib/basic_named_scopes.rb
CHANGED
@@ -12,6 +12,8 @@
|
|
12
12
|
# All named scopes are called the same, except for +include+, which is now
|
13
13
|
# called +with+, because +include+ is a reserved method.
|
14
14
|
#
|
15
|
+
# Also, the scope +conditions+ is aliased as +where+, just as in ActiveRecord 3.
|
16
|
+
#
|
15
17
|
# Reuse them by making class methods:
|
16
18
|
#
|
17
19
|
# class Post < ActiveRecord::Base
|
@@ -49,6 +51,9 @@ module BasicNamedScopes
|
|
49
51
|
# These are the normal parameters that will be turned into named scopes.
|
50
52
|
FIND_PARAMETERS = [:conditions, :order, :group, :having, :limit, :offset, :joins, :select, :from]
|
51
53
|
|
54
|
+
# These are aliased parameters. The keys are scope names, the values are the option they represent.
|
55
|
+
FIND_ALIASES = { :where => :conditions, :with => :include }
|
56
|
+
|
52
57
|
# These are the parameters that want a boolean.
|
53
58
|
FIND_BOOLEAN_SWITCHES = [:readonly, :lock]
|
54
59
|
|
@@ -62,10 +67,12 @@ module BasicNamedScopes
|
|
62
67
|
end
|
63
68
|
|
64
69
|
def apply_basic_named_scopes(model)
|
65
|
-
model.named_scope(:with, expand_into_array(:include))
|
66
70
|
FIND_PARAMETERS.each do |parameter|
|
67
71
|
model.named_scope(parameter, expand_into_array(parameter))
|
68
72
|
end
|
73
|
+
FIND_ALIASES.each do |name, parameter|
|
74
|
+
model.named_scope(name, expand_into_array(parameter))
|
75
|
+
end
|
69
76
|
FIND_BOOLEAN_SWITCHES.each do |parameter|
|
70
77
|
model.named_scope(parameter, default_to_true(parameter))
|
71
78
|
end
|
@@ -50,6 +50,12 @@ describe "BasicNamedScopes" do
|
|
50
50
|
Post.with(:author).to_a
|
51
51
|
end
|
52
52
|
|
53
|
+
it "should use a scope named 'where' but internally use 'conditions' as parameter" do
|
54
|
+
subject = Post.where("published = ?", true)
|
55
|
+
subject.class.should be_scope
|
56
|
+
subject.should == [ @published ]
|
57
|
+
end
|
58
|
+
|
53
59
|
[:conditions, :order, :group, :having, :limit, :offset, :joins, :with, :select, :from].each do |option|
|
54
60
|
it "should known #{option} ActiveRecord::Base.find" do
|
55
61
|
Post.send(option).class.should be_scope
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: basic_named_scopes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Iain Hecker
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-01-10 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -30,7 +30,17 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
33
|
+
version: 1.3.0
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: activerecord
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - <
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 3.0.pre
|
34
44
|
version:
|
35
45
|
description: Make your queries prettier and more reusable by having a named scope for every find-parameter. As easy as Post.include(:author, :comments)
|
36
46
|
email: iain@iain.nl
|