merged_default_scopes 0.0.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/.document +5 -0
- data/.gitconfig +2 -0
- data/.gitignore +22 -0
- data/.rspec +1 -0
- data/Gemfile +5 -0
- data/History.markdown +10 -0
- data/LICENSE +20 -0
- data/README.markdown +30 -0
- data/Rakefile +40 -0
- data/VERSION +1 -0
- data/autotest/discover.rb +1 -0
- data/lib/merged_default_scopes.rb +29 -0
- data/merged_default_scopes.gemspec +59 -0
- data/spec/merged_default_scopes_spec.rb +33 -0
- data/spec/spec_helper.rb +4 -0
- metadata +94 -0
data/.document
ADDED
data/.gitconfig
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/History.markdown
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 David Chelimsky
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# merged\_default\_scopes
|
2
|
+
|
3
|
+
module SomeSoftDeletablePlugin
|
4
|
+
def self.included(mod)
|
5
|
+
mod.default_scope :conditions => {:deleted_at => nil}
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class SomeModel < ActiveRecord::Base
|
10
|
+
include SomeSoftDeletablePlugin # that may or may not be setting a default_scope
|
11
|
+
|
12
|
+
default_scope :order => :name
|
13
|
+
end
|
14
|
+
|
15
|
+
# default_scope => {:find => {:order => :name, :conditions => {:deleted_at => nil}}}
|
16
|
+
#
|
17
|
+
# ... and all is right with the world
|
18
|
+
|
19
|
+
## Note on Patches/Pull Requests
|
20
|
+
|
21
|
+
* Fork the project.
|
22
|
+
* Make your feature addition or bug fix.
|
23
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
24
|
+
* Commit, do not mess with rakefile, version, or history.
|
25
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
26
|
+
* Send me a pull request. Bonus points for topic branches.
|
27
|
+
|
28
|
+
## Copyright
|
29
|
+
|
30
|
+
Copyright (c) 2010 David Chelimsky and Brain Tatnall. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "merged_default_scopes"
|
8
|
+
gem.summary = %Q{the name says it all}
|
9
|
+
gem.description = %Q{modify behavior of default_scope method to merge rather than override}
|
10
|
+
gem.email = "dchelimsky@gmail.com,btatnall@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/dchelimsky/merged_default_scopes"
|
12
|
+
gem.authors = ["David Chelimsky", "Brian Tatnall"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 2.0.0.beta.8"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rspec/core/rake_task'
|
22
|
+
Rspec::Core::RakeTask.new(:spec)
|
23
|
+
|
24
|
+
Rspec::Core::RakeTask.new(:rcov) do |spec|
|
25
|
+
spec.rcov = true
|
26
|
+
end
|
27
|
+
|
28
|
+
task :spec => :check_dependencies
|
29
|
+
|
30
|
+
task :default => :spec
|
31
|
+
|
32
|
+
require 'rake/rdoctask'
|
33
|
+
Rake::RDocTask.new do |rdoc|
|
34
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
35
|
+
|
36
|
+
rdoc.rdoc_dir = 'rdoc'
|
37
|
+
rdoc.title = "merged_default_scopes #{version}"
|
38
|
+
rdoc.rdoc_files.include('README*')
|
39
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
40
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
@@ -0,0 +1 @@
|
|
1
|
+
Autotest.add_discovery { "rspec2" }
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "active_record"
|
2
|
+
require "active_record/base"
|
3
|
+
|
4
|
+
module MergedDefaultScopes
|
5
|
+
module ClassMethods
|
6
|
+
def default_scope(options = {})
|
7
|
+
if default_scoping.empty?
|
8
|
+
super(options)
|
9
|
+
else
|
10
|
+
with_scope(:find => options, :create => options[:conditions].is_a?(Hash) ? options[:conditions] : {}) do
|
11
|
+
scoped_methods << scoped_methods.last
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.included(mod)
|
18
|
+
mod.class_eval do
|
19
|
+
class << self
|
20
|
+
define_method :inherited do |sub|
|
21
|
+
sub.extend ClassMethods
|
22
|
+
super(sub)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
ActiveRecord::Base.send :include, MergedDefaultScopes
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{merged_default_scopes}
|
8
|
+
s.version = "0.0.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["David Chelimsky", "Brian Tatnall"]
|
12
|
+
s.date = %q{2010-05-12}
|
13
|
+
s.description = %q{modify behavior of default_scope method to merge rather than override}
|
14
|
+
s.email = %q{dchelimsky@gmail.com,btatnall@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitconfig",
|
22
|
+
".gitignore",
|
23
|
+
".rspec",
|
24
|
+
"Gemfile",
|
25
|
+
"History.markdown",
|
26
|
+
"LICENSE",
|
27
|
+
"README.markdown",
|
28
|
+
"Rakefile",
|
29
|
+
"VERSION",
|
30
|
+
"autotest/discover.rb",
|
31
|
+
"lib/merged_default_scopes.rb",
|
32
|
+
"merged_default_scopes.gemspec",
|
33
|
+
"spec/merged_default_scopes_spec.rb",
|
34
|
+
"spec/spec_helper.rb"
|
35
|
+
]
|
36
|
+
s.homepage = %q{http://github.com/dchelimsky/merged_default_scopes}
|
37
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = %q{1.3.6}
|
40
|
+
s.summary = %q{the name says it all}
|
41
|
+
s.test_files = [
|
42
|
+
"spec/merged_default_scopes_spec.rb",
|
43
|
+
"spec/spec_helper.rb"
|
44
|
+
]
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
|
+
s.specification_version = 3
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.8"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.8"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.8"])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
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
|
19
|
+
|
20
|
+
describe MergedDefaultScopes do
|
21
|
+
describe "#default_scope" do
|
22
|
+
before(:each) do
|
23
|
+
SomeModel.__send__ :default_scope, :order => :name
|
24
|
+
SomeModel.__send__ :default_scope, :conditions => {:deleted_at => nil}
|
25
|
+
end
|
26
|
+
|
27
|
+
it "merges multiple calls" do
|
28
|
+
SomeModel.__send__(:scope, :find).
|
29
|
+
should == {:order => :name, :conditions => {:deleted_at => nil}}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: merged_default_scopes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- David Chelimsky
|
13
|
+
- Brian Tatnall
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-05-12 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 2
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
- beta
|
33
|
+
- 8
|
34
|
+
version: 2.0.0.beta.8
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: modify behavior of default_scope method to merge rather than override
|
38
|
+
email: dchelimsky@gmail.com,btatnall@gmail.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- LICENSE
|
45
|
+
- README.markdown
|
46
|
+
files:
|
47
|
+
- .document
|
48
|
+
- .gitconfig
|
49
|
+
- .gitignore
|
50
|
+
- .rspec
|
51
|
+
- Gemfile
|
52
|
+
- History.markdown
|
53
|
+
- LICENSE
|
54
|
+
- README.markdown
|
55
|
+
- Rakefile
|
56
|
+
- VERSION
|
57
|
+
- autotest/discover.rb
|
58
|
+
- lib/merged_default_scopes.rb
|
59
|
+
- merged_default_scopes.gemspec
|
60
|
+
- spec/merged_default_scopes_spec.rb
|
61
|
+
- spec/spec_helper.rb
|
62
|
+
has_rdoc: true
|
63
|
+
homepage: http://github.com/dchelimsky/merged_default_scopes
|
64
|
+
licenses: []
|
65
|
+
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options:
|
68
|
+
- --charset=UTF-8
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.3.6
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: the name says it all
|
92
|
+
test_files:
|
93
|
+
- spec/merged_default_scopes_spec.rb
|
94
|
+
- spec/spec_helper.rb
|