activerecord-endoscope 0.0.1 → 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.
- checksums.yaml +4 -4
- data/README.md +9 -2
- data/lib/active_record/endoscope.rb +5 -6
- data/lib/active_record/endoscope/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b2bf489b3f724243c06baf3af05a3df2a2c67bf
|
4
|
+
data.tar.gz: 38131b96090c359b3b0f3e0b1f17cd79c654cb39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d01545bbe9af660d03de99577905b9a082289b1ea2036fe7903c06c8f6f34035509dd3512af6e7cdd0594ceee56a1321cc2c833fac2cf001c5528e0c8de04b5
|
7
|
+
data.tar.gz: 123226f8c6ac312066d7e7cd5bce8115c8655ca73ac6fa4d4365a82be5badbe644bd2b17762a686ad4f948bb7f89f83a8d168c7fb363dfdaaf94f52d32fe7838
|
data/README.md
CHANGED
@@ -19,6 +19,9 @@ class User < ActiveRecord::Base
|
|
19
19
|
scope :minor, -> {
|
20
20
|
where(age: 0..19)
|
21
21
|
}
|
22
|
+
scope :aged, ->(age) {
|
23
|
+
where(age: age)
|
24
|
+
}
|
22
25
|
scope :have_no_email, -> {
|
23
26
|
where(email: nil)
|
24
27
|
}
|
@@ -36,18 +39,22 @@ u.admin? # => false
|
|
36
39
|
u.not_admin? # => true
|
37
40
|
u.admin_or_manager? # => false
|
38
41
|
u.minor? # => false
|
42
|
+
u.aged?(20) # => true
|
39
43
|
u.has_no_email? # => false
|
40
44
|
u.has_email? # => true
|
41
45
|
```
|
42
46
|
|
43
|
-
With
|
47
|
+
**With NO SQL execution.**
|
44
48
|
|
45
49
|
|
46
50
|
## Restriction
|
47
51
|
|
48
52
|
Limited queries have been supported yet.
|
49
53
|
|
50
|
-
SQL literal such as `where('email IS NOT NULL')` is not supported
|
54
|
+
SQL literal such as `where('email IS NOT NULL')` is not supported.
|
55
|
+
|
56
|
+
Supported queries are shown in:
|
57
|
+
https://github.com/tkawa/arel_ruby/blob/master/lib/arel/visitors/ruby.rb
|
51
58
|
|
52
59
|
If your query is not supported, you can override the method manually.
|
53
60
|
|
@@ -2,15 +2,14 @@ require 'active_record/endoscope/version'
|
|
2
2
|
|
3
3
|
module ActiveRecord
|
4
4
|
module Endoscope
|
5
|
-
def scope(name,
|
5
|
+
def scope(name, body, &block)
|
6
6
|
super
|
7
7
|
|
8
8
|
instance_method_name = "#{name.to_s.sub(/^have_/, 'has_')}?"
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
ENDOSCOPE
|
9
|
+
|
10
|
+
define_method(instance_method_name) do |*args|
|
11
|
+
self.class.send(name, *args).build_arel.to_ruby.call([self]).present?
|
12
|
+
end
|
14
13
|
end
|
15
14
|
end
|
16
15
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-endoscope
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Toru KAWAMURA
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|