edge_rider 0.3.2 → 2.0.0
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.
- checksums.yaml +5 -5
- data/.github/workflows/test.yml +99 -0
- data/.rspec +1 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +45 -0
- data/Gemfile +1 -0
- data/{gemfiles/Gemfile.4.2.mysql2 → Gemfile.4.2.mysql2} +4 -3
- data/{gemfiles/Gemfile.4.2.mysql2.lock → Gemfile.4.2.mysql2.lock} +32 -22
- data/{gemfiles/Gemfile.4.2.pg → Gemfile.4.2.pg} +3 -2
- data/{gemfiles/Gemfile.4.2.pg.lock → Gemfile.4.2.pg.lock} +30 -20
- data/Gemfile.5.2.mysql2 +17 -0
- data/{gemfiles/Gemfile.5.1.mysql2.lock → Gemfile.5.2.mysql2.lock} +34 -22
- data/{gemfiles/Gemfile.5.1.mysql2 → Gemfile.5.2.pg} +7 -5
- data/{gemfiles/Gemfile.5.1.pg.lock → Gemfile.5.2.pg.lock} +32 -20
- data/{gemfiles/Gemfile.5.1.pg → Gemfile.6.1.pg} +4 -3
- data/Gemfile.6.1.pg.lock +78 -0
- data/Gemfile.lock +1 -0
- data/README.md +96 -91
- data/Rakefile +1 -1
- data/edge_rider.gemspec +24 -15
- data/lib/edge_rider/collect_column.rb +8 -15
- data/lib/edge_rider/origin_class.rb +2 -10
- data/lib/edge_rider/preload_associations.rb +7 -0
- data/lib/edge_rider/scoped.rb +1 -1
- data/lib/edge_rider/to_id_query.rb +1 -1
- data/lib/edge_rider/traverse_association.rb +9 -5
- data/lib/edge_rider/util.rb +18 -19
- data/lib/edge_rider/version.rb +1 -1
- data/lib/edge_rider.rb +0 -1
- metadata +24 -37
- data/.travis.yml +0 -68
- data/gemfiles/Gemfile.2.3.mysql2 +0 -16
- data/gemfiles/Gemfile.2.3.mysql2.lock +0 -37
- data/gemfiles/Gemfile.3.2.mysql2 +0 -16
- data/gemfiles/Gemfile.3.2.mysql2.lock +0 -62
- data/lib/edge_rider/to_sql.rb +0 -13
- data/spec/edge_rider/collect_column_spec.rb +0 -85
- data/spec/edge_rider/collect_ids_spec.rb +0 -108
- data/spec/edge_rider/origin_class_spec.rb +0 -32
- data/spec/edge_rider/preload_associations_spec.rb +0 -15
- data/spec/edge_rider/scoped_spec.rb +0 -55
- data/spec/edge_rider/to_id_query_spec.rb +0 -29
- data/spec/edge_rider/to_sql_spec.rb +0 -14
- data/spec/edge_rider/traverse_association_spec.rb +0 -134
- data/spec/edge_rider/util_spec.rb +0 -5
- data/spec/spec_helper.rb +0 -12
- data/spec/support/database.rb +0 -34
- data/spec/support/database.sample.yml +0 -10
- data/spec/support/database.travis.yml +0 -9
- data/spec/support/models.rb +0 -92
@@ -1,15 +1,17 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
# Runtime dependencies
|
4
|
-
gem 'activerecord', '~>5.
|
5
|
-
gem '
|
4
|
+
gem 'activerecord', '~>5.2.3'
|
5
|
+
gem 'pg'
|
6
|
+
gem 'i18n', '<=1.5.1' # Required to support tests for Ruby 2.2.x
|
6
7
|
|
7
8
|
# Development dependencies
|
8
9
|
gem 'rake'
|
9
10
|
gem 'database_cleaner'
|
10
|
-
gem 'rspec'
|
11
11
|
gem 'has_defaults' # used by test models
|
12
|
-
gem '
|
12
|
+
gem 'rspec'
|
13
|
+
gem 'gemika', '>=0.5.0'
|
14
|
+
gem 'pry-byebug'
|
13
15
|
|
14
16
|
# Gem under test
|
15
|
-
gem 'edge_rider', :
|
17
|
+
gem 'edge_rider', path: '.'
|
@@ -1,33 +1,43 @@
|
|
1
1
|
PATH
|
2
|
-
remote:
|
2
|
+
remote: .
|
3
3
|
specs:
|
4
|
-
edge_rider (0.
|
5
|
-
activerecord
|
4
|
+
edge_rider (2.0.0)
|
5
|
+
activerecord (>= 3.2)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (5.
|
11
|
-
activesupport (= 5.
|
12
|
-
activerecord (5.
|
13
|
-
activemodel (= 5.
|
14
|
-
activesupport (= 5.
|
15
|
-
arel (
|
16
|
-
activesupport (5.
|
10
|
+
activemodel (5.2.3)
|
11
|
+
activesupport (= 5.2.3)
|
12
|
+
activerecord (5.2.3)
|
13
|
+
activemodel (= 5.2.3)
|
14
|
+
activesupport (= 5.2.3)
|
15
|
+
arel (>= 9.0)
|
16
|
+
activesupport (5.2.3)
|
17
17
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
|
-
i18n (
|
18
|
+
i18n (>= 0.7, < 2)
|
19
19
|
minitest (~> 5.1)
|
20
20
|
tzinfo (~> 1.1)
|
21
|
-
arel (
|
22
|
-
|
21
|
+
arel (9.0.0)
|
22
|
+
byebug (10.0.2)
|
23
|
+
coderay (1.1.2)
|
24
|
+
concurrent-ruby (1.1.5)
|
23
25
|
database_cleaner (1.6.1)
|
24
26
|
diff-lcs (1.3)
|
25
|
-
gemika (0.
|
27
|
+
gemika (0.5.0)
|
26
28
|
has_defaults (0.4.4)
|
27
29
|
activerecord
|
28
|
-
i18n (
|
29
|
-
|
30
|
+
i18n (1.5.1)
|
31
|
+
concurrent-ruby (~> 1.0)
|
32
|
+
method_source (0.9.2)
|
33
|
+
minitest (5.11.3)
|
30
34
|
pg (0.20.0)
|
35
|
+
pry (0.12.2)
|
36
|
+
coderay (~> 1.1.0)
|
37
|
+
method_source (~> 0.9.0)
|
38
|
+
pry-byebug (3.6.0)
|
39
|
+
byebug (~> 10.0)
|
40
|
+
pry (~> 0.10)
|
31
41
|
rake (12.0.0)
|
32
42
|
rspec (3.6.0)
|
33
43
|
rspec-core (~> 3.6.0)
|
@@ -43,21 +53,23 @@ GEM
|
|
43
53
|
rspec-support (~> 3.6.0)
|
44
54
|
rspec-support (3.6.0)
|
45
55
|
thread_safe (0.3.6)
|
46
|
-
tzinfo (1.2.
|
56
|
+
tzinfo (1.2.5)
|
47
57
|
thread_safe (~> 0.1)
|
48
58
|
|
49
59
|
PLATFORMS
|
50
60
|
ruby
|
51
61
|
|
52
62
|
DEPENDENCIES
|
53
|
-
activerecord (~> 5.
|
63
|
+
activerecord (~> 5.2.3)
|
54
64
|
database_cleaner
|
55
65
|
edge_rider!
|
56
|
-
gemika
|
66
|
+
gemika (>= 0.5.0)
|
57
67
|
has_defaults
|
68
|
+
i18n (<= 1.5.1)
|
58
69
|
pg
|
70
|
+
pry-byebug
|
59
71
|
rake
|
60
72
|
rspec
|
61
73
|
|
62
74
|
BUNDLED WITH
|
63
|
-
|
75
|
+
2.2.26
|
@@ -1,7 +1,7 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
# Runtime dependencies
|
4
|
-
gem 'activerecord', '~>
|
4
|
+
gem 'activerecord', '~>6.1.3'
|
5
5
|
gem 'pg'
|
6
6
|
|
7
7
|
# Development dependencies
|
@@ -9,7 +9,8 @@ gem 'rake'
|
|
9
9
|
gem 'database_cleaner'
|
10
10
|
gem 'has_defaults' # used by test models
|
11
11
|
gem 'rspec'
|
12
|
-
gem 'gemika'
|
12
|
+
gem 'gemika', '>=0.5.0'
|
13
|
+
gem 'pry-byebug'
|
13
14
|
|
14
15
|
# Gem under test
|
15
|
-
gem 'edge_rider', :
|
16
|
+
gem 'edge_rider', path: '.'
|
data/Gemfile.6.1.pg.lock
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
edge_rider (2.0.0)
|
5
|
+
activerecord (>= 3.2)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (6.1.3)
|
11
|
+
activesupport (= 6.1.3)
|
12
|
+
activerecord (6.1.3)
|
13
|
+
activemodel (= 6.1.3)
|
14
|
+
activesupport (= 6.1.3)
|
15
|
+
activesupport (6.1.3)
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
+
i18n (>= 1.6, < 2)
|
18
|
+
minitest (>= 5.1)
|
19
|
+
tzinfo (~> 2.0)
|
20
|
+
zeitwerk (~> 2.3)
|
21
|
+
byebug (11.1.3)
|
22
|
+
coderay (1.1.3)
|
23
|
+
concurrent-ruby (1.1.8)
|
24
|
+
database_cleaner (2.0.1)
|
25
|
+
database_cleaner-active_record (~> 2.0.0)
|
26
|
+
database_cleaner-active_record (2.0.0)
|
27
|
+
activerecord (>= 5.a)
|
28
|
+
database_cleaner-core (~> 2.0.0)
|
29
|
+
database_cleaner-core (2.0.1)
|
30
|
+
diff-lcs (1.4.4)
|
31
|
+
gemika (0.5.0)
|
32
|
+
has_defaults (0.4.4)
|
33
|
+
activerecord
|
34
|
+
i18n (1.8.9)
|
35
|
+
concurrent-ruby (~> 1.0)
|
36
|
+
method_source (1.0.0)
|
37
|
+
minitest (5.14.4)
|
38
|
+
pg (1.2.3)
|
39
|
+
pry (0.13.1)
|
40
|
+
coderay (~> 1.1)
|
41
|
+
method_source (~> 1.0)
|
42
|
+
pry-byebug (3.9.0)
|
43
|
+
byebug (~> 11.0)
|
44
|
+
pry (~> 0.13.0)
|
45
|
+
rake (13.0.3)
|
46
|
+
rspec (3.10.0)
|
47
|
+
rspec-core (~> 3.10.0)
|
48
|
+
rspec-expectations (~> 3.10.0)
|
49
|
+
rspec-mocks (~> 3.10.0)
|
50
|
+
rspec-core (3.10.1)
|
51
|
+
rspec-support (~> 3.10.0)
|
52
|
+
rspec-expectations (3.10.1)
|
53
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
54
|
+
rspec-support (~> 3.10.0)
|
55
|
+
rspec-mocks (3.10.2)
|
56
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
57
|
+
rspec-support (~> 3.10.0)
|
58
|
+
rspec-support (3.10.2)
|
59
|
+
tzinfo (2.0.4)
|
60
|
+
concurrent-ruby (~> 1.0)
|
61
|
+
zeitwerk (2.4.2)
|
62
|
+
|
63
|
+
PLATFORMS
|
64
|
+
ruby
|
65
|
+
|
66
|
+
DEPENDENCIES
|
67
|
+
activerecord (~> 6.1.3)
|
68
|
+
database_cleaner
|
69
|
+
edge_rider!
|
70
|
+
gemika (>= 0.5.0)
|
71
|
+
has_defaults
|
72
|
+
pg
|
73
|
+
pry-byebug
|
74
|
+
rake
|
75
|
+
rspec
|
76
|
+
|
77
|
+
BUNDLED WITH
|
78
|
+
2.2.26
|
data/Gemfile.lock
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Gemfile.6.1.pg.lock
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
Edge Rider [](https://github.com/makandra/edge_rider/actions)
|
3
2
|
|
4
|
-
Power tools for ActiveRecord relations (scopes)
|
5
|
-
-------------------------------------------------
|
3
|
+
## Power tools for ActiveRecord relations (scopes)
|
6
4
|
|
7
5
|
In ActiveRecord, relations (or scopes) allow you to construct complex queries piece-by-piece
|
8
6
|
and then trigger a query or update at a precisely defined moment. If you write any kind
|
@@ -14,9 +12,7 @@ Edge Rider was created with two intents:
|
|
14
12
|
2. Provide a stable API for working with relations across multiple versions of Rails (since
|
15
13
|
Rails has a tradition of breaking details of its relation API every other release).
|
16
14
|
|
17
|
-
|
18
|
-
Usage
|
19
|
-
-----
|
15
|
+
## Usage
|
20
16
|
|
21
17
|
### Traversing a relation along an association
|
22
18
|
|
@@ -25,20 +21,26 @@ returns a new relation by "pivoting" around a named association.
|
|
25
21
|
|
26
22
|
Say we have a `Post` model and each `Post` belongs to an author:
|
27
23
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
24
|
+
```ruby
|
25
|
+
class Post < ActiveRecord::Base
|
26
|
+
belongs_to :author
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
32
30
|
To turn a relation of posts into a relation of its authors:
|
33
31
|
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
```ruby
|
33
|
+
posts = Post.where(archived: false)
|
34
|
+
authors = posts.traverse_association(:author)
|
35
|
+
```
|
36
|
+
|
37
37
|
You can traverse multiple associations in a single call.
|
38
38
|
E.g. to turn a relation of posts into a relation of all posts of their authors:
|
39
39
|
|
40
|
-
|
41
|
-
|
40
|
+
```ruby
|
41
|
+
posts = Post.where(archived: false)
|
42
|
+
posts_by_same_authors = posts.traverse_association(:author, :posts)
|
43
|
+
```
|
42
44
|
|
43
45
|
*Implementation note:* The traversal is achieved internally by collecting all foreign keys in the current relation
|
44
46
|
and return a new relation with an `IN(...)` query (which is very efficient even for many thousand keys).
|
@@ -56,10 +58,12 @@ its ID.
|
|
56
58
|
Edge Rider has a better way. Your relations gain a method `#collect_ids` that will
|
57
59
|
fetch all IDs in a single query without instantiating a single ActiveRecord object:
|
58
60
|
|
59
|
-
|
60
|
-
|
61
|
+
```ruby
|
62
|
+
posts = Post.where(archived: false)
|
63
|
+
post_ids = posts.collect_ids
|
64
|
+
```
|
61
65
|
|
62
|
-
*
|
66
|
+
*Implementation note:* `#collect_ids` delegates to [`#pluck`](https://apidock.com/rails/ActiveRecord/Calculations/pluck),
|
63
67
|
which can be used for the same purpose.
|
64
68
|
|
65
69
|
|
@@ -68,33 +72,39 @@ which can be used for the same purpose.
|
|
68
72
|
When writing a method that filters by record IDs, you can make it more useful by accepting
|
69
73
|
any kind of argument that can be turned into a list of IDs:
|
70
74
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
75
|
+
```ruby
|
76
|
+
Post.by_author(1)
|
77
|
+
Post.by_author([1, 2, 3])
|
78
|
+
Post.by_author(Author.find(1))
|
79
|
+
Post.by_author([Author.find(1), Author.find(2)])
|
80
|
+
Post.by_author(Author.active)
|
81
|
+
```
|
76
82
|
|
77
83
|
For this use case Edge Rider defines `#collect_ids` on many different types:
|
78
84
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
85
|
+
```ruby
|
86
|
+
Post.where(id: [1, 2]).collect_ids # => [1, 2]
|
87
|
+
[Post.find(1), Post.find(2)].collect_ids # => [1, 2]
|
88
|
+
Post.find(1).collect_ids # => [1]
|
89
|
+
[1, 2, 3].collect_ids # => [1, 2, 3]
|
90
|
+
1.collect_ids # => [1]
|
91
|
+
```
|
84
92
|
|
85
93
|
You can now write `Post.by_author` from the example above without a single `if` or `case`:
|
86
94
|
|
87
|
-
|
88
|
-
|
89
|
-
|
95
|
+
```ruby
|
96
|
+
class Post < ActiveRecord::Base
|
97
|
+
|
98
|
+
belongs_to :author
|
99
|
+
|
100
|
+
def self.for_author(author_or_authors)
|
101
|
+
where(author_id: author_or_authors.collect_ids)
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
```
|
90
106
|
|
91
|
-
def self.for_author(author_or_authors)
|
92
|
-
where(:author_id => author_or_authors.collect_ids)
|
93
|
-
end
|
94
107
|
|
95
|
-
end
|
96
|
-
|
97
|
-
|
98
108
|
### Efficiently collect all values in a relation's column
|
99
109
|
|
100
110
|
You often want to ask a relation for an array of all values ofin a given column.
|
@@ -106,42 +116,27 @@ its column value.
|
|
106
116
|
Edge Rider has a better way. Your relations gain a method `#collect_column` that will
|
107
117
|
fetch all column values in a single query without instantiating a single ActiveRecord object:
|
108
118
|
|
109
|
-
|
110
|
-
|
119
|
+
```ruby
|
120
|
+
posts = Post.where(archived: false)
|
121
|
+
subjects = posts.collect_column(:subject)
|
122
|
+
```
|
111
123
|
|
112
|
-
*Implementation note:*
|
124
|
+
*Implementation note:* `#collect_column` delegates to [`#pluck`](https://apidock.com/rails/ActiveRecord/Calculations/pluck),
|
113
125
|
which can be used for the same effect.
|
114
126
|
|
115
127
|
#### Collect unique values in a relation's column
|
116
128
|
|
117
|
-
If you only care about *unique* values, use the
|
129
|
+
If you only care about *unique* values, use the `distinct: true` option:
|
118
130
|
|
119
|
-
|
120
|
-
|
131
|
+
```ruby
|
132
|
+
posts = Post.where(archived: false)
|
133
|
+
distinct_subjects = posts.collect_column(:subject, distinct: true)
|
134
|
+
```
|
121
135
|
|
122
136
|
With this options duplicates are discarded by the database before making their way into Ruby.
|
123
137
|
|
124
|
-
*Implementation note:*
|
125
|
-
which can be used for the same effect.
|
126
|
-
|
127
|
-
|
128
|
-
### Retrieve the SQL a relation would produce
|
129
|
-
|
130
|
-
Sometimes it is useful to ask a relation which SQL query it would trigger,
|
131
|
-
if it was evaluated right now. For this, Edge Rider gives your relations a method
|
132
|
-
`#to_sql`:
|
133
|
-
|
134
|
-
# Rails 2 scope
|
135
|
-
Post.scoped(:conditions => { :id => [1, 2] }).to_sql
|
136
|
-
# => "SELECT `posts`.* FROM `posts` WHERE `posts.id` IN (1, 2)"
|
137
|
-
|
138
|
-
# Rails 3 relation
|
139
|
-
Post.where(:id => [1, 2]).to_sql
|
140
|
-
# => "SELECT `posts`.* FROM `posts` WHERE `posts.id` IN (1, 2)"
|
141
|
-
|
142
|
-
*Implementation note*: Rails 3+ implements `#to_sql`. Edge Rider backports this method to Rails 2 so you can use it
|
143
|
-
regardless of your Rails version.
|
144
|
-
|
138
|
+
*Implementation note:* The `:distinct` option is implemented with [`#uniq`](https://apidock.com/rails/ActiveRecord/QueryMethods/uniq)
|
139
|
+
or [`#distinct`](https://apidock.com/rails/ActiveRecord/QueryMethods/distinct) which can be used for the same effect.
|
145
140
|
|
146
141
|
### Simplify a complex relation for better chainability
|
147
142
|
|
@@ -155,40 +150,51 @@ mashes together strings that mostly happen to look like a MySQL query in the end
|
|
155
150
|
|
156
151
|
Edge Rider gives your relations a new method `#to_id_query`:
|
157
152
|
|
158
|
-
|
153
|
+
```ruby
|
154
|
+
Site.joins(user).where(:users: { name: 'Bruce' }).to_id_query
|
155
|
+
```
|
159
156
|
|
160
157
|
`#to_id_query` will immediately run an SQL query where it collects all the IDs that match your relation:
|
161
158
|
|
162
|
-
|
159
|
+
```sql
|
160
|
+
SELECT sites.id FROM sites INNER JOIN users WHERE sites.user_id = sites.id AND users.name = 'Bruce'
|
161
|
+
```
|
163
162
|
|
164
163
|
It now uses these IDs to return a new relation that has **no joins** and a single condition on the `id` column:
|
165
164
|
|
166
|
-
|
165
|
+
```sql
|
166
|
+
SELECT * FROM sites WHERE sites.user_id IN (3, 17, 103)
|
167
|
+
```
|
167
168
|
|
168
169
|
|
169
170
|
### Preload associations for loaded ActiveRecords
|
170
171
|
|
171
172
|
Sometimes you want to fetch associations for records that you already instantiated, e.g. when it has deeply nested associations.
|
172
173
|
|
173
|
-
Edge Rider gives your model classes a method
|
174
|
+
Edge Rider gives your model classes and instances a method `preload_associations`. The method can be used to preload associations for loaded objects like this:
|
174
175
|
|
175
|
-
|
176
|
-
|
176
|
+
```ruby
|
177
|
+
@user = User.find(params[:id])
|
178
|
+
User.preload_associations [@user], { threads: { posts: :author }, messages: :sender }
|
179
|
+
# or
|
180
|
+
user.preload_associations { threads: { posts: :author }, messages: :sender }
|
181
|
+
```
|
177
182
|
|
178
|
-
*Implementation note*: Rails
|
183
|
+
*Implementation note*: Rails 3.0 already has a method [`.preload_associations`](https://apidock.com/rails/ActiveRecord/AssociationPreload/ClassMethods/preload_associations)
|
179
184
|
which Edge Rider merely makes public. Edge Rider ports this method forward to Rails 3.1+.
|
180
185
|
|
181
186
|
|
182
|
-
|
183
187
|
### Retrieve the class a relation is based on
|
184
188
|
|
185
189
|
Edge Rider gives your relations a method `#origin_class` that returns the class the relation is based on.
|
186
190
|
This is useful e.g. to perform unscoped record look-up.
|
187
191
|
|
188
|
-
|
189
|
-
|
192
|
+
```ruby
|
193
|
+
Post.recent.origin_class
|
194
|
+
# => Post
|
195
|
+
```
|
190
196
|
|
191
|
-
Note that `#origin_class` it roughly equivalent to the blockless form of [`unscoped`](
|
197
|
+
Note that `#origin_class` it roughly equivalent to the blockless form of [`unscoped`](https://apidock.com/rails/ActiveRecord/Scoping/Default/ClassMethods/unscoped) from Rails 3.2+,
|
192
198
|
but it works consistently across all Rails versions.
|
193
199
|
|
194
200
|
|
@@ -199,11 +205,13 @@ Edge Rider ports `Model.scoped` forward to Rails 4+ (taken from
|
|
199
205
|
enables you to consistently turn models into scopes or narrow down scopes
|
200
206
|
across all versions of Rails.
|
201
207
|
|
202
|
-
|
203
|
-
|
208
|
+
```ruby
|
209
|
+
User.scoped # just calls User.all in Rails 4
|
210
|
+
User.active.scoped(conditions: { admin: true })
|
211
|
+
```
|
204
212
|
|
205
|
-
*Implementation note*: Rails
|
206
|
-
[`.scoped`](
|
213
|
+
*Implementation note*: Rails 3 already have a method
|
214
|
+
[`.scoped`](https://apidock.com/rails/ActiveRecord/Scoping/Named/ClassMethods/scoped) which Edge Rider does not touch. Rails 4 has removed this method and
|
207
215
|
splits its functionality into the query methods known from Rails 3 (`.where`,
|
208
216
|
`.order` etc.) and an `.all` method that just returns a scope.
|
209
217
|
|
@@ -213,24 +221,24 @@ slightly different in all versions of Rails (see
|
|
213
221
|
methods are not modified.
|
214
222
|
|
215
223
|
|
216
|
-
Installation
|
217
|
-
------------
|
224
|
+
## Installation
|
218
225
|
|
219
226
|
In your `Gemfile` say:
|
220
227
|
|
221
|
-
|
228
|
+
```ruby
|
229
|
+
gem 'edge_rider'
|
230
|
+
```
|
222
231
|
|
223
232
|
Now run `bundle install` and restart your server.
|
224
233
|
|
225
234
|
|
226
|
-
Development
|
227
|
-
-----------
|
235
|
+
## Development
|
228
236
|
|
229
237
|
- There are tests in `spec`. We only accept PRs with tests.
|
230
|
-
- We currently develop using Ruby
|
238
|
+
- We currently develop using the Ruby version in `.ruby-version`. It is required to change the Ruby Version to cover all Rails version or just use Travis CI.
|
231
239
|
- Put your database credentials into `spec/support/database.yml`. There's a `database.sample.yml` you can use as a template.
|
232
240
|
- Create a database `edge_rider_test` in both MySQL and PostgreSQL.
|
233
|
-
- There are gem bundles in
|
241
|
+
- There are gem bundles in the project root for each combination of ActiveRecord version and database type that we support.
|
234
242
|
- You can bundle all test applications by saying `bundle exec rake matrix:install`
|
235
243
|
- You can run specs from the project root by saying `bundle exec rake matrix:spec`. This will run all gemfiles compatible with your current Ruby.
|
236
244
|
|
@@ -241,9 +249,6 @@ If you would like to contribute:
|
|
241
249
|
- Send me a pull request.
|
242
250
|
|
243
251
|
|
244
|
-
Credits
|
245
|
-
-------
|
252
|
+
## Credits
|
246
253
|
|
247
254
|
Henning Koch from [makandra](http://makandra.com/)
|
248
|
-
|
249
|
-
|