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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ffc4aa6014a91480e0d25a484bda55984815727
4
- data.tar.gz: eb1ee58bb40c9dbda50cd7b65fda57abc2189523
3
+ metadata.gz: 6b2bf489b3f724243c06baf3af05a3df2a2c67bf
4
+ data.tar.gz: 38131b96090c359b3b0f3e0b1f17cd79c654cb39
5
5
  SHA512:
6
- metadata.gz: 246dbe488914684dac0ff3a684479164fb79959fa0a48aa2f46058113f0e03f18383f404ebe0268bbbea7f52d335759b0a67c398b34256c9a5ab98a7e018b8cd
7
- data.tar.gz: a3710de8de3a0eb1b6e9376ad2a5b942577aece07e885250a5b8f76de40d49430c038fa1befaaedab2b17c0ad9144d9f0d86510f8c082ee29eb772f7bc6c17a6
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 no SQL execution.
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, scope_options = {})
5
+ def scope(name, body, &block)
6
6
  super
7
7
 
8
8
  instance_method_name = "#{name.to_s.sub(/^have_/, 'has_')}?"
9
- class_eval <<-ENDOSCOPE, __FILE__, __LINE__ + 1
10
- def #{instance_method_name}
11
- self.class.#{name}.arel.to_ruby.call([self]).present?
12
- end
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
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module Endoscope
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  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.1
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 00:00:00.000000000 Z
11
+ date: 2013-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord