imyou 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/imyou/models.rb +47 -9
- data/lib/imyou/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 437f6453c5c674668419f8f5968eeb9d14836e4dac03b0894cf64c9b0f73fee4
|
4
|
+
data.tar.gz: 892461025e8a962f5d4738a10d56f768c3a2ed53dcf1641a53acc8ce9b6afd58
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad812533dff9b9265d46ef784f65c9f3035f8ddca8742ac3c02755e8c976bc408e7c64e49511135c03731c87d4f30e41520d85c46214d339178c3a8531c9e858
|
7
|
+
data.tar.gz: 360976116e0941de8f7d5e848096bf17bcc733aa0d0de20e4a256883da665e0ea0cd44d50e63d931962629b9d2b193defbc93cbe1f7fc15cbaa7c58d58a4f634
|
data/Gemfile.lock
CHANGED
data/lib/imyou/models.rb
CHANGED
@@ -4,22 +4,60 @@ module Imyou
|
|
4
4
|
false
|
5
5
|
end
|
6
6
|
|
7
|
-
def has_imyou
|
7
|
+
def has_imyou(name_column=nil)
|
8
8
|
class_eval do
|
9
9
|
|
10
10
|
has_many :imyou_nicknames, class_name: 'Imyou::Nickname', as: :model, dependent: :destroy
|
11
11
|
scope :with_nicknames, -> { eager_load(:imyou_nicknames) }
|
12
12
|
|
13
|
-
scope :match_by_nickname, ->(nickname) do
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
scope :match_by_nickname, ->(nickname, with_name_column: true) do
|
14
|
+
if Gem::Version.new(ActiveRecord.version) >= Gem::Version.new(5)
|
15
|
+
records = self.with_nicknames.where(Imyou::Nickname.arel_table[:name].eq(nickname))
|
16
|
+
unless name_column.nil? || with_name_column == false
|
17
|
+
records.or!(self.with_nicknames.where(name_column => nickname))
|
18
|
+
end
|
19
|
+
else
|
20
|
+
arel_nickname_column = Imyou::Nickname.arel_table[:name]
|
21
|
+
records = if name_column.nil? || with_name_column == false
|
22
|
+
self.with_nicknames.where(
|
23
|
+
arel_nickname_column.eq(nickname)
|
24
|
+
)
|
25
|
+
else
|
26
|
+
arel_name_column = self.arel_table[name_column]
|
27
|
+
self.with_nicknames.where(
|
28
|
+
arel_nickname_column.eq(nickname).or(
|
29
|
+
arel_name_column.eq(nickname)
|
30
|
+
)
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
records
|
17
35
|
end
|
18
36
|
|
19
|
-
scope :partial_match_by_nickname, ->(nickname) do
|
20
|
-
|
21
|
-
|
22
|
-
|
37
|
+
scope :partial_match_by_nickname, ->(nickname, with_name_column: true) do
|
38
|
+
if Gem::Version.new(ActiveRecord.version) >= Gem::Version.new(5)
|
39
|
+
records = self.with_nicknames.where(Imyou::Nickname.arel_table[:name].matches("%#{sanitize_sql_like(nickname)}%"))
|
40
|
+
unless name_column.nil? || with_name_column == false
|
41
|
+
records.or!(self.with_nicknames.where(
|
42
|
+
self.arel_table[name_column].matches("%#{sanitize_sql_like(nickname)}%"))
|
43
|
+
)
|
44
|
+
end
|
45
|
+
else
|
46
|
+
arel_nickname_column = Imyou::Nickname.arel_table[:name]
|
47
|
+
records = if name_column.nil? || with_name_column == false
|
48
|
+
self.with_nicknames.where(
|
49
|
+
arel_nickname_column.matches("%#{sanitize_sql_like(nickname)}%")
|
50
|
+
)
|
51
|
+
else
|
52
|
+
arel_name_column = self.arel_table[name_column]
|
53
|
+
self.with_nicknames.where(
|
54
|
+
arel_nickname_column.matches("%#{sanitize_sql_like(nickname)}%").or(
|
55
|
+
arel_name_column.matches("%#{sanitize_sql_like(nickname)}%")
|
56
|
+
)
|
57
|
+
)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
records
|
23
61
|
end
|
24
62
|
|
25
63
|
def self.has_imyou?
|
data/lib/imyou/version.rb
CHANGED