activerecord-autoscope 0.1.0 → 0.2.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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +30 -28
- data/lib/activerecord/auto_scope/scope_methods.rb +2 -0
- data/lib/activerecord/auto_scope/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b25256fc1f2418a53b6b4ff9339b75deb6aadac63f24c56da07b9085d8f6429
|
4
|
+
data.tar.gz: 3d1488d0136e6966f010623033dddfcf77c5cf75bedcd3a2f4aeb0af020b6600
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31f82763f6b3617d9401151e1b459b065e7c0308a2103f7f5f287fb482f1a356185353483a5a8acdc77ebffa5f440a07a15978da80b79edb970fa403765e81ec
|
7
|
+
data.tar.gz: abd3799fcc61c8478bb882c9cb9a7952cf5b43de709a9ddb43375aea2955064397ac414e837313afdf235a150523b9a6e76da88064d37e1a136a3b04547031b3
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# ActiveRecord::AutoScope
|
2
2
|
|
3
|
-
This gem automatically defines scope methods which we often implement
|
3
|
+
This gem automatically defines **scope methods which we often implement**
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -22,37 +22,39 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
This gem automatically defines these scope methods **without configuration**
|
24
24
|
|
25
|
-
These APIs are similar as [
|
25
|
+
These APIs are similar as [Ransack](https://github.com/activerecord-hackery/ransack/)'s one, but these scope methods are simple implementations.
|
26
26
|
|
27
27
|
Please check its [implementation](https://github.com/yhirano55/activerecord-autoscope/blob/master/lib/activerecord/auto_scope/scope_methods.rb) if you're interested in.
|
28
28
|
|
29
|
-
| Type |
|
29
|
+
| Type | Scope method | Description | Notes |
|
30
30
|
| ---- | --------- | ----------- | ----- |
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
| `:integer` |
|
42
|
-
| `:integer` |
|
43
|
-
| `:
|
44
|
-
| `:
|
45
|
-
| `:string`, `:text` |
|
46
|
-
| `:string`, `:text` |
|
47
|
-
| `:string`, `:text` |
|
48
|
-
| `:string`, `:text` |
|
49
|
-
| `:
|
50
|
-
| `:
|
51
|
-
| `:date`, `:datetime` |
|
52
|
-
| `:date`, `:datetime` |
|
53
|
-
| `:date`, `:datetime` |
|
54
|
-
| `:
|
55
|
-
| `:
|
31
|
+
| All | `#{col}_eq(val)` | equal | |
|
32
|
+
| All | `#{col}_not_eq(val)` | not equal | |
|
33
|
+
| All | `#{col}_is(val)` | equal | |
|
34
|
+
| All | `#{col}_is_not(val)` | not equal | |
|
35
|
+
| All | `#{col}_null` | is null | |
|
36
|
+
| All | `#{col}_not_null` | is not null | |
|
37
|
+
| All | `#{col}_present` | not null and not empty | SQL: `col IS NOT NULL AND col != ''` |
|
38
|
+
| All | `#{col}_blank` | null or empty | SQL: `col IS NULL OR col = ''` |
|
39
|
+
| All | `#{col}_asc` | ascending order | |
|
40
|
+
| All | `#{col}_desc` | descending order | |
|
41
|
+
| `:integer` | `#{col}_gt(val)` | greater than | |
|
42
|
+
| `:integer` | `#{col}_gteq(val)` | greater than or equal | |
|
43
|
+
| `:integer` | `#{col}_lt(val)` | less than | |
|
44
|
+
| `:integer` | `#{col}_lteq(val)` | less than or equal | |
|
45
|
+
| `:string`, `:text` | `#{col}_start(val)` | starts with | SQL: `col LIKE 'value%'` |
|
46
|
+
| `:string`, `:text` | `#{col}_not_start(val)` | does not start with | |
|
47
|
+
| `:string`, `:text` | `#{col}_end(val)` | ends with | SQL: `col LIKE '%value'` |
|
48
|
+
| `:string`, `:text` | `#{col}_not_end(val)` | does not end with | |
|
49
|
+
| `:string`, `:text` | `#{col}_cont(val)` | contains | SQL: `col LIKE '%value%'` |
|
50
|
+
| `:string`, `:text` | `#{col}_not_cont(val)` | does not contain | |
|
51
|
+
| `:date`, `:datetime` | `#{col}_after(val)` | after | |
|
52
|
+
| `:date`, `:datetime` | `#{col}_on_or_after(val)` | on or after | |
|
53
|
+
| `:date`, `:datetime` | `#{col}_before(val)` | before | |
|
54
|
+
| `:date`, `:datetime` | `#{col}_on_or_before(val)` | on or before | |
|
55
|
+
| `:date`, `:datetime` | `#{col}_between(range)` | between | |
|
56
|
+
| `:boolean` | `#{col}` | true | SQL: `col IS true` |
|
57
|
+
| `:boolean` | `not_#{col}` | false | |
|
56
58
|
|
57
59
|
### Manually settings
|
58
60
|
|
@@ -16,6 +16,8 @@ module ActiveRecord
|
|
16
16
|
scope("#{attr_name}_not_null", -> { where.not(attr_name => nil) })
|
17
17
|
scope("#{attr_name}_present", -> { where("#{table_name}.#{attr_name} IS NOT NULL AND #{table_name}.#{attr_name} != ''") })
|
18
18
|
scope("#{attr_name}_blank", -> { where("#{table_name}.#{attr_name} IS NULL OR #{table_name}.#{attr_name} = ''") })
|
19
|
+
scope("#{attr_name}_asc", -> { order(attr_name => :asc) })
|
20
|
+
scope("#{attr_name}_desc", -> { order(attr_name => :desc) })
|
19
21
|
|
20
22
|
case column.type
|
21
23
|
when :integer
|