scopy 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -7
- data/lib/scopy/created_at_scopes.rb +1 -1
- data/lib/scopy/name_scopes.rb +2 -2
- data/lib/scopy/version.rb +1 -1
- data/test/name_scopes_test.rb +5 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4ede8244e2248535c20fc15d5669551186f8f88
|
4
|
+
data.tar.gz: 8bbd7483d0fa9c75ed28d6c14d7299d7e7a2db48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 056782b0d1a89a1f3f573c6482a95a605b209903a0ca445722a59e3b906b1e762f72a9b7aa55c4f9e4ba8230ac5d6086ab411714120dfce3d292c27b8afba413
|
7
|
+
data.tar.gz: 5c6225a571a37db8077ba0e00df990304b100e01da477a15b3f2d7d6117b40787eebb8e97ecbdbeb3900757c54228c0ca6c75149d5e57c98d0a62ec67c1a8b2c
|
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# Scopy
|
2
2
|
|
3
3
|
[![Build Status](https://api.travis-ci.org/neighborland/scopy.png)](https://travis-ci.org/neighborland/scopy)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/scopy.png)](http://badge.fury.io/rb/scopy)
|
4
5
|
|
5
|
-
Scopy provides common ActiveRecord utility scopes as ActiveSupport concerns.
|
6
|
+
Scopy provides common ActiveRecord utility scopes as ActiveSupport model concerns.
|
6
7
|
|
7
8
|
Common scopes for the following attributes are provided:
|
8
9
|
|
@@ -28,6 +29,7 @@ Include the concern modules you would like to use in your models:
|
|
28
29
|
class Dog < ActiveRecord::Base
|
29
30
|
include Scopy::CreatedAtScopes
|
30
31
|
include Scopy::IdScopes
|
32
|
+
include Scopy::NameScopes
|
31
33
|
```
|
32
34
|
|
33
35
|
The following examples assume you have a model named `Dog`:
|
@@ -76,16 +78,16 @@ Dog.excluding(dog)
|
|
76
78
|
##### Scopy::NameScopes
|
77
79
|
|
78
80
|
```ruby
|
79
|
-
Dog.name_like('
|
81
|
+
Dog.name_like('snOOp')
|
80
82
|
# => dogs with names containing 'snoop' (case insensitive)
|
81
83
|
|
82
|
-
Dog.name_like('
|
83
|
-
# => dogs with names containing '
|
84
|
+
Dog.name_like('Snoop', case_sensitive: true)
|
85
|
+
# => dogs with names containing 'Snoop' (case sensitive)
|
84
86
|
|
85
|
-
Dog.name_starts_with('
|
87
|
+
Dog.name_starts_with('snOOp')
|
86
88
|
# => dogs with names starting with 'snoop' (case insensitive)
|
87
89
|
|
88
|
-
Dog.name_starts_with('
|
89
|
-
# => dogs with names starting with '
|
90
|
+
Dog.name_starts_with('Snoop', case_sensitive: true)
|
91
|
+
# => dogs with names starting with 'Snoop' (case sensitive)
|
90
92
|
```
|
91
93
|
|
@@ -3,7 +3,7 @@ module Scopy
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
|
-
scope :newest, ->{ order("#{self.table_name}.created_at
|
6
|
+
scope :newest, ->{ order("#{self.table_name}.created_at DESC") }
|
7
7
|
scope :oldest, ->{ order("#{self.table_name}.created_at") }
|
8
8
|
|
9
9
|
scope :created_since, ->(since) do
|
data/lib/scopy/name_scopes.rb
CHANGED
@@ -9,12 +9,12 @@ module Scopy
|
|
9
9
|
included do
|
10
10
|
scope :name_like, ->(text, options={}) do
|
11
11
|
cs = options[:case_sensitive]
|
12
|
-
where("#{_lhs_name_column(cs)} LIKE
|
12
|
+
where("#{_lhs_name_column(cs)} LIKE ?", "%#{_rhs_name_value(text, cs)}%")
|
13
13
|
end
|
14
14
|
|
15
15
|
scope :name_starts_with, ->(text, options={}) do
|
16
16
|
cs = options[:case_sensitive]
|
17
|
-
where("#{_lhs_name_column(cs)} LIKE
|
17
|
+
where("#{_lhs_name_column(cs)} LIKE ?", "#{_rhs_name_value(text, cs)}%")
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
data/lib/scopy/version.rb
CHANGED
data/test/name_scopes_test.rb
CHANGED
@@ -19,6 +19,11 @@ class NameScopesTest < Test::Unit::TestCase
|
|
19
19
|
assert_empty Dog.name_like("cat", case_sensitive: true)
|
20
20
|
end
|
21
21
|
|
22
|
+
should "find with quotes" do
|
23
|
+
o_dogg = Dog.create(name: "Snoop O'Doggly")
|
24
|
+
assert Dog.name_like("O'Dogg").include?(o_dogg)
|
25
|
+
end
|
26
|
+
|
22
27
|
should "find case insensitive" do
|
23
28
|
assert Dog.name_like("doG").include?(@dog)
|
24
29
|
assert_empty Dog.name_like("cat")
|