sexy_scopes 0.6.0 → 0.7.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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -6
  3. data/README.md +56 -7
  4. data/lib/arel/visitors_extensions.rb +89 -0
  5. data/lib/sexy_scopes.rb +33 -10
  6. data/lib/sexy_scopes/active_record.rb +0 -1
  7. data/lib/sexy_scopes/active_record/class_methods.rb +5 -16
  8. data/lib/sexy_scopes/active_record/dynamic_methods.rb +26 -21
  9. data/lib/sexy_scopes/arel.rb +10 -28
  10. data/lib/sexy_scopes/arel/expression_methods.rb +9 -0
  11. data/lib/sexy_scopes/arel/math.rb +28 -0
  12. data/lib/sexy_scopes/arel/nodes/regexp_matches.rb +12 -0
  13. data/lib/sexy_scopes/arel/predicate_methods.rb +13 -38
  14. data/lib/sexy_scopes/arel/predications.rb +67 -0
  15. data/lib/sexy_scopes/arel/typecasting.rb +21 -0
  16. data/lib/sexy_scopes/version.rb +1 -1
  17. metadata +53 -50
  18. data/.gitignore +0 -4
  19. data/.travis.yml +0 -19
  20. data/Gemfile +0 -2
  21. data/Rakefile +0 -13
  22. data/ci/Gemfile.ar-edge +0 -8
  23. data/ci/Gemfile.ar3.1 +0 -8
  24. data/ci/Gemfile.ar3.2 +0 -8
  25. data/lib/sexy_scopes/arel/boolean_methods.rb +0 -20
  26. data/lib/sexy_scopes/arel/math_methods.rb +0 -25
  27. data/lib/sexy_scopes/expression_wrappers.rb +0 -7
  28. data/lib/sexy_scopes/predicate_wrappers.rb +0 -6
  29. data/lib/sexy_scopes/wrappers.rb +0 -13
  30. data/sexy_scopes.gemspec +0 -32
  31. data/spec/active_record_spec.rb +0 -73
  32. data/spec/boolean_methods_spec.rb +0 -45
  33. data/spec/fixtures/models.rb +0 -2
  34. data/spec/fixtures/schema.rb +0 -9
  35. data/spec/matchers/be_extended_by.rb +0 -6
  36. data/spec/matchers/convert_to_sql.rb +0 -13
  37. data/spec/math_methods_spec.rb +0 -55
  38. data/spec/predicate_methods_spec.rb +0 -38
  39. data/spec/spec_helper.rb +0 -28
@@ -0,0 +1,28 @@
1
+ module SexyScopes
2
+ module Arel
3
+ module Math
4
+ include Typecasting if SexyScopes.arel_6?
5
+
6
+ def *(other)
7
+ SexyScopes.extend_expression(super)
8
+ end
9
+
10
+ def +(other)
11
+ SexyScopes.extend_expression(super)
12
+ end
13
+
14
+ def -(other)
15
+ SexyScopes.extend_expression(super)
16
+ end
17
+
18
+ def /(other)
19
+ SexyScopes.extend_expression(super)
20
+ end
21
+
22
+ def coerce(other)
23
+ expression = ::Arel.sql(other.to_s)
24
+ [SexyScopes.extend_expression(expression), self]
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,12 @@
1
+ module SexyScopes
2
+ module Arel
3
+ module Nodes
4
+ class RegexpMatches < ::Arel::Nodes::InfixOperation
5
+ def initialize(left, right)
6
+ right = Regexp.try_convert(right) || Regexp.compile(right.to_s)
7
+ super(:REGEXP, left, right)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,50 +1,25 @@
1
1
  module SexyScopes
2
2
  module Arel
3
3
  module PredicateMethods
4
- def eq(other)
5
- extend_predicate(super)
6
- end
7
- alias == eq
8
-
9
- def in(other)
10
- extend_predicate(super)
11
- end
12
-
13
- def matches(other)
14
- extend_predicate(super)
15
- end
16
- alias =~ matches
17
-
18
- def does_not_match(other)
19
- extend_predicate(super)
20
- end
21
- alias !~ does_not_match
22
-
23
- def gteq(other)
24
- extend_predicate(super)
25
- end
26
- alias >= gteq
27
-
28
- def gt(other)
29
- extend_predicate(super)
30
- end
31
- alias > gt
4
+ # <tt>Arel::Grouping</tt> nodes didn't include <tt>Arel::Predications</tt> before Arel 3, but <tt>or</tt>
5
+ # returns an <tt>Arel::Grouping</tt> node (surrounds the SQL <tt>OR</tt> clause with parenthesis).
6
+ # Since ActiveRecord 3.1 depends on Arel 2, including the module here ensures the methods will exist.
7
+ include ::Arel::Predications
32
8
 
33
- def lt(other)
34
- extend_predicate(super)
9
+ def not
10
+ SexyScopes.extend_predicate(super)
35
11
  end
36
- alias < lt
12
+ alias ~ not
37
13
 
38
- def lteq(other)
39
- extend_predicate(super)
14
+ def or(other)
15
+ SexyScopes.extend_predicate(super)
40
16
  end
41
- alias <= lteq
17
+ alias | or
42
18
 
43
- def not_eq(other)
44
- extend_predicate(super)
19
+ def and(other)
20
+ SexyScopes.extend_predicate(super)
45
21
  end
46
- alias != not_eq
22
+ alias & and
47
23
  end
48
24
  end
49
25
  end
50
-
@@ -0,0 +1,67 @@
1
+ module SexyScopes
2
+ module Arel
3
+ module Predications
4
+ def eq(other)
5
+ SexyScopes.extend_predicate(super)
6
+ end
7
+ alias == eq
8
+
9
+ def in(other)
10
+ SexyScopes.extend_predicate(super)
11
+ end
12
+
13
+ def matches(other)
14
+ if Regexp === other
15
+ matches_regexp(other)
16
+ else
17
+ SexyScopes.extend_predicate(super)
18
+ end
19
+ end
20
+ alias =~ matches
21
+
22
+ def does_not_match(other)
23
+ if Regexp === other
24
+ does_not_match_regexp(other)
25
+ else
26
+ SexyScopes.extend_predicate(super)
27
+ end
28
+ end
29
+ alias !~ does_not_match
30
+
31
+ def matches_regexp(other)
32
+ predicate = Arel::Nodes::RegexpMatches.new(self, other)
33
+ SexyScopes.extend_predicate(predicate)
34
+ end
35
+
36
+ def does_not_match_regexp(other)
37
+ matches_regexp(other).not
38
+ end
39
+
40
+ def gteq(other)
41
+ SexyScopes.extend_predicate(super)
42
+ end
43
+ alias >= gteq
44
+
45
+ def gt(other)
46
+ SexyScopes.extend_predicate(super)
47
+ end
48
+ alias > gt
49
+
50
+ def lt(other)
51
+ SexyScopes.extend_predicate(super)
52
+ end
53
+ alias < lt
54
+
55
+ def lteq(other)
56
+ SexyScopes.extend_predicate(super)
57
+ end
58
+ alias <= lteq
59
+
60
+ def not_eq(other)
61
+ SexyScopes.extend_predicate(super)
62
+ end
63
+ alias != not_eq
64
+ end
65
+ end
66
+ end
67
+
@@ -0,0 +1,21 @@
1
+ module SexyScopes
2
+ module Arel
3
+ module Typecasting
4
+ def *(other)
5
+ super SexyScopes.type_cast(other, self)
6
+ end
7
+
8
+ def +(other)
9
+ super SexyScopes.type_cast(other, self)
10
+ end
11
+
12
+ def -(other)
13
+ super SexyScopes.type_cast(other, self)
14
+ end
15
+
16
+ def /(other)
17
+ super SexyScopes.type_cast(other, self)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,7 +1,7 @@
1
1
  module SexyScopes
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 6
4
+ MINOR = 7
5
5
  TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sexy_scopes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Lebeau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-29 00:00:00.000000000 Z
11
+ date: 2014-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: appraisal
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -53,61 +67,75 @@ dependencies:
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0.9'
55
69
  - !ruby/object:Gem::Dependency
56
- name: rails
70
+ name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - ~>
60
74
  - !ruby/object:Gem::Version
61
- version: '3.0'
75
+ version: '2.0'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - ~>
67
81
  - !ruby/object:Gem::Version
68
- version: '3.0'
82
+ version: '2.0'
69
83
  - !ruby/object:Gem::Dependency
70
- name: rspec
84
+ name: sqlite3
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - ~>
74
88
  - !ruby/object:Gem::Version
75
- version: '2.0'
89
+ version: '1.0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - ~>
81
95
  - !ruby/object:Gem::Version
82
- version: '2.0'
96
+ version: '1.0'
83
97
  - !ruby/object:Gem::Dependency
84
- name: sqlite3
98
+ name: mysql2
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - ~>
88
102
  - !ruby/object:Gem::Version
89
- version: '1.0'
103
+ version: '0.3'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - ~>
95
109
  - !ruby/object:Gem::Version
96
- version: '1.0'
110
+ version: '0.3'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pg
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '0.8'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '0.8'
97
125
  - !ruby/object:Gem::Dependency
98
126
  name: redcarpet
99
127
  requirement: !ruby/object:Gem::Requirement
100
128
  requirements:
101
129
  - - ~>
102
130
  - !ruby/object:Gem::Version
103
- version: '2.2'
131
+ version: '3.0'
104
132
  type: :development
105
133
  prerelease: false
106
134
  version_requirements: !ruby/object:Gem::Requirement
107
135
  requirements:
108
136
  - - ~>
109
137
  - !ruby/object:Gem::Version
110
- version: '2.2'
138
+ version: '3.0'
111
139
  - !ruby/object:Gem::Dependency
112
140
  name: yard
113
141
  requirement: !ruby/object:Gem::Requirement
@@ -143,39 +171,23 @@ executables: []
143
171
  extensions: []
144
172
  extra_rdoc_files: []
145
173
  files:
146
- - .gitignore
147
- - .travis.yml
148
174
  - CHANGELOG.md
149
- - Gemfile
150
- - LICENSE
151
175
  - README.md
152
- - Rakefile
153
- - ci/Gemfile.ar-edge
154
- - ci/Gemfile.ar3.1
155
- - ci/Gemfile.ar3.2
156
- - lib/sexy_scopes.rb
157
- - lib/sexy_scopes/active_record.rb
176
+ - LICENSE
177
+ - lib/arel/visitors_extensions.rb
158
178
  - lib/sexy_scopes/active_record/class_methods.rb
159
179
  - lib/sexy_scopes/active_record/dynamic_methods.rb
160
- - lib/sexy_scopes/arel.rb
161
- - lib/sexy_scopes/arel/boolean_methods.rb
162
- - lib/sexy_scopes/arel/math_methods.rb
180
+ - lib/sexy_scopes/active_record.rb
181
+ - lib/sexy_scopes/arel/expression_methods.rb
182
+ - lib/sexy_scopes/arel/math.rb
183
+ - lib/sexy_scopes/arel/nodes/regexp_matches.rb
163
184
  - lib/sexy_scopes/arel/predicate_methods.rb
164
- - lib/sexy_scopes/expression_wrappers.rb
165
- - lib/sexy_scopes/predicate_wrappers.rb
185
+ - lib/sexy_scopes/arel/predications.rb
186
+ - lib/sexy_scopes/arel/typecasting.rb
187
+ - lib/sexy_scopes/arel.rb
166
188
  - lib/sexy_scopes/railtie.rb
167
189
  - lib/sexy_scopes/version.rb
168
- - lib/sexy_scopes/wrappers.rb
169
- - sexy_scopes.gemspec
170
- - spec/active_record_spec.rb
171
- - spec/boolean_methods_spec.rb
172
- - spec/fixtures/models.rb
173
- - spec/fixtures/schema.rb
174
- - spec/matchers/be_extended_by.rb
175
- - spec/matchers/convert_to_sql.rb
176
- - spec/math_methods_spec.rb
177
- - spec/predicate_methods_spec.rb
178
- - spec/spec_helper.rb
190
+ - lib/sexy_scopes.rb
179
191
  homepage: https://github.com/samleb/sexy_scopes
180
192
  licenses:
181
193
  - MIT
@@ -196,18 +208,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
208
  version: '0'
197
209
  requirements: []
198
210
  rubyforge_project:
199
- rubygems_version: 2.0.2
211
+ rubygems_version: 2.0.3
200
212
  signing_key:
201
213
  specification_version: 4
202
214
  summary: Write beautiful and expressive ActiveRecord scopes without SQL.
203
- test_files:
204
- - spec/active_record_spec.rb
205
- - spec/boolean_methods_spec.rb
206
- - spec/fixtures/models.rb
207
- - spec/fixtures/schema.rb
208
- - spec/matchers/be_extended_by.rb
209
- - spec/matchers/convert_to_sql.rb
210
- - spec/math_methods_spec.rb
211
- - spec/predicate_methods_spec.rb
212
- - spec/spec_helper.rb
215
+ test_files: []
213
216
  has_rdoc:
data/.gitignore DELETED
@@ -1,4 +0,0 @@
1
- Gemfile.lock
2
- coverage
3
- pkg
4
- doc
data/.travis.yml DELETED
@@ -1,19 +0,0 @@
1
- language: ruby
2
- bundler_args: --without development --standalone
3
- rvm:
4
- - 1.9.2
5
- - 1.9.3
6
- - 2.0.0
7
- - jruby-19mode
8
- - rbx-19mode
9
- gemfile:
10
- - ci/Gemfile.ar3.1
11
- - ci/Gemfile.ar3.2
12
- - ci/Gemfile.ar-edge
13
- matrix:
14
- exclude:
15
- - rvm: 1.9.2
16
- gemfile: ci/Gemfile.ar-edge
17
- branches:
18
- only:
19
- - master
data/Gemfile DELETED
@@ -1,2 +0,0 @@
1
- source 'https://rubygems.org'
2
- gemspec
data/Rakefile DELETED
@@ -1,13 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
-
4
- desc "Run specifications"
5
- RSpec::Core::RakeTask.new(:spec)
6
-
7
- desc "Measure test coverage"
8
- task :cov do
9
- ENV['COVERAGE'] = '1'
10
- Rake::Task['spec'].invoke
11
- end
12
-
13
- task :default => :spec