activerecord-autoscope 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 777a569281b2e5c3094260664c157e5dc686f0a0a66b100b01a69934bc3c2c3f
4
- data.tar.gz: 74f54e9f786b70788e95d8dddece0e7fba1a87ba3bf6defd7fd596f78e31a6a7
3
+ metadata.gz: 5b25256fc1f2418a53b6b4ff9339b75deb6aadac63f24c56da07b9085d8f6429
4
+ data.tar.gz: 3d1488d0136e6966f010623033dddfcf77c5cf75bedcd3a2f4aeb0af020b6600
5
5
  SHA512:
6
- metadata.gz: d60e542cd7d3ff042c8ca8eda7ce0f81e6d3d1e2fba25f622d228a2e6a6cb811015682ed3ee14c208d4c8fbe9f4dcee76cec796eec1d4deb4245fe57b4ee1898
7
- data.tar.gz: a7e40c224bdf06159021eb944b67f8e3b002a9d6627f274c3c3cd949275375791779f39894e339d52e568a52a636dc14577f30d92a9bec069e7a023b5b0a774c
6
+ metadata.gz: 31f82763f6b3617d9401151e1b459b065e7c0308a2103f7f5f287fb482f1a356185353483a5a8acdc77ebffa5f440a07a15978da80b79edb970fa403765e81ec
7
+ data.tar.gz: abd3799fcc61c8478bb882c9cb9a7952cf5b43de709a9ddb43375aea2955064397ac414e837313afdf235a150523b9a6e76da88064d37e1a136a3b04547031b3
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- activerecord-autoscope (0.1.0)
4
+ activerecord-autoscope (0.2.0)
5
5
  activerecord (>= 5.2)
6
6
 
7
7
  GEM
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 [ransack](https://github.com/activerecord-hackery/ransack/)'s one, but these scope methods are simple implementations.
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 | Predicate | Description | Notes |
29
+ | Type | Scope method | Description | Notes |
30
30
  | ---- | --------- | ----------- | ----- |
31
- | all | `*_eq` | equal | |
32
- | all | `*_not_eq` | not equal | |
33
- | all | `*_is` | equal | |
34
- | all | `*_is_not` | not equal | |
35
- | all | `*_null` | is null | |
36
- | all | `*_not_null` | is not null | |
37
- | all | `*_present` | not null and not empty | |
38
- | all | `*_blank` | null or empty | |
39
- | `:integer` | `*_gt` | greater than | |
40
- | `:integer` | `*_gteq` | greater than or equal | |
41
- | `:integer` | `*_lt` | less than | |
42
- | `:integer` | `*_lteq` | less than or equal | |
43
- | `:string`, `:text` | `*_start` | starts with | SQL: `col LIKE 'value%'` |
44
- | `:string`, `:text` | `*_not_start` | does not start with | |
45
- | `:string`, `:text` | `*_end` | ends with | SQL: `col LIKE '%value'` |
46
- | `:string`, `:text` | `*_not_end` | does not end with | |
47
- | `:string`, `:text` | `*_cont` | contains | SQL: `col LIKE '%value%'` |
48
- | `:string`, `:text` | `*_not_cont` | does not contain | |
49
- | `:date`, `:datetime` | `*_after` | after | |
50
- | `:date`, `:datetime` | `*_on_or_after` | on or after | |
51
- | `:date`, `:datetime` | `*_before` | before | |
52
- | `:date`, `:datetime` | `*_on_or_before` | on or before | |
53
- | `:date`, `:datetime` | `*_between` | between | |
54
- | `:boolean` | `*` | true | SQL: `col IS true` |
55
- | `:boolean` | `not_*` | false | |
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveRecord
4
4
  module AutoScope
5
- VERSION = '0.1.0'.freeze
5
+ VERSION = '0.2.0'.freeze
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-autoscope
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshiyuki Hirano