wildcard_scopes 0.0.2 → 0.0.3
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 -5
- data/lib/wildcard_scopes/railtie.rb +0 -3
- data/lib/wildcard_scopes/version.rb +1 -1
- data/spec/spec_helper.rb +2 -4
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -6,11 +6,8 @@ Use ActiveRecord scopes with dynamic names.
|
|
6
6
|
|
7
7
|
# config/initializers/wildcard_scopes.rb
|
8
8
|
|
9
|
-
# Global scopes
|
10
|
-
|
11
|
-
# Wildcard scope should be wrapped in a proc. a is array of matches.
|
12
|
-
wildcard_scope /descend_by_(.*)/, proc { |a| order("#{table_name}.#{a.first} DESC") }
|
13
|
-
}
|
9
|
+
# Global scopes. Wildcard scope should be wrapped in a proc. a is array of matches.
|
10
|
+
ActiveRecord::Base.wildcard_scope /descend_by_(.*)/, proc { |a| order("#{table_name}.#{a.first} DESC") }
|
14
11
|
|
15
12
|
# app/models/user.rb
|
16
13
|
class User < ActiveRecord::Base
|
@@ -1,10 +1,7 @@
|
|
1
1
|
module WildcardScopes
|
2
2
|
class Railtie < ::Rails::Railtie
|
3
|
-
config.wildcard_scopes = proc { }
|
4
|
-
|
5
3
|
ActiveSupport.on_load :active_record do
|
6
4
|
ActiveRecord::Base.send(:include, WildcardScopes::Base)
|
7
|
-
ActiveRecord::Base.instance_exec(&WildcardScopes::Railtie.config.wildcard_scopes)
|
8
5
|
end
|
9
6
|
end
|
10
7
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,10 +4,6 @@ require 'rubygems'
|
|
4
4
|
require 'bundler/setup'
|
5
5
|
require 'wildcard_scopes'
|
6
6
|
|
7
|
-
WildcardScopes::Railtie.config.wildcard_scopes = proc {
|
8
|
-
ActiveRecord::Base.wildcard_scope /ascend_by_(.*)/, proc { |a| order("#{table_name}.#{a.first} ASC") }
|
9
|
-
}
|
10
|
-
|
11
7
|
ActiveRecord::Base.establish_connection(
|
12
8
|
"adapter" => "sqlite3",
|
13
9
|
"database" => ":memory:"
|
@@ -19,6 +15,8 @@ ActiveRecord::Schema.define :version => 0 do
|
|
19
15
|
end
|
20
16
|
end
|
21
17
|
|
18
|
+
ActiveRecord::Base.wildcard_scope /ascend_by_(.*)/, proc { |a| order("#{table_name}.#{a.first} ASC") }
|
19
|
+
|
22
20
|
class User < ActiveRecord::Base
|
23
21
|
wildcard_scope /descend_by_(.*)/, proc { |a| order("#{table_name}.#{a.first} DESC") }
|
24
22
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wildcard_scopes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Victor Sokolov
|