imyou 1.1.3 → 1.2.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 +26 -10
- 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: 2ea37cab3c8ce4f35113a47972b4936655a977040adee8ea2bd6b59f01ad5168
|
4
|
+
data.tar.gz: 7de5c7103f8e133355f0c08ad0fa6e7056e33c9101930c7326a965aa09083022
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ddaf339b9c10bfb339280fd05eb4dc827b46ca6f163f3031a7e95e292ff8eea6624f5660f605f6ba3827f22a95bb60f8fc1348ec118843f3a2560059ca12861
|
7
|
+
data.tar.gz: 3f7a465be25dd666cab0aa6a3e427f9ed49b836f3329c3ab5ae96771a156b1e3334b5fd1d1ab9c445abdabcafa368bfe03ad435e07cea2fa6d94b182f5436dff
|
data/Gemfile.lock
CHANGED
data/lib/imyou/models.rb
CHANGED
@@ -7,24 +7,32 @@ module Imyou
|
|
7
7
|
def has_imyou(name_column=nil)
|
8
8
|
class_eval do
|
9
9
|
|
10
|
-
has_many :imyou_nicknames, class_name: 'Imyou::Nickname', as: :model, dependent: :destroy
|
11
|
-
scope :with_nicknames, -> {
|
10
|
+
has_many :imyou_nicknames, -> { order(id: :asc) }, class_name: 'Imyou::Nickname', as: :model, dependent: :destroy
|
11
|
+
scope :with_nicknames, -> { preload(:imyou_nicknames) }
|
12
12
|
|
13
13
|
scope :match_by_nickname, ->(nickname, with_name_column: true) do
|
14
14
|
if Gem::Version.new(ActiveRecord.version) >= Gem::Version.new(5)
|
15
|
-
records = self.
|
15
|
+
records = self.left_outer_joins(:imyou_nicknames).where(Imyou::Nickname.arel_table[:name].eq(nickname))
|
16
16
|
unless name_column.nil? || with_name_column == false
|
17
|
-
records.or!(self.
|
17
|
+
records.or!(self.left_outer_joins(:imyou_nicknames).where(name_column => nickname))
|
18
18
|
end
|
19
19
|
else
|
20
|
+
joined_records = self.joins(<<~SQL
|
21
|
+
LEFT OUTER JOIN #{Imyou::Nickname.quoted_table_name}
|
22
|
+
ON
|
23
|
+
#{Imyou::Nickname.quoted_table_name}.#{connection.quote_column_name(:model_id)} = #{self.quoted_table_name}.#{connection.quote_column_name(:id)}
|
24
|
+
AND
|
25
|
+
#{Imyou::Nickname.quoted_table_name}.#{connection.quote_column_name(:model_type)} = #{connection.quote(self.name)}
|
26
|
+
SQL
|
27
|
+
)
|
20
28
|
arel_nickname_column = Imyou::Nickname.arel_table[:name]
|
21
29
|
records = if name_column.nil? || with_name_column == false
|
22
|
-
|
30
|
+
joined_records.where(
|
23
31
|
arel_nickname_column.eq(nickname)
|
24
32
|
)
|
25
33
|
else
|
26
34
|
arel_name_column = self.arel_table[name_column]
|
27
|
-
|
35
|
+
joined_records.where(
|
28
36
|
arel_nickname_column.eq(nickname).or(
|
29
37
|
arel_name_column.eq(nickname)
|
30
38
|
)
|
@@ -36,21 +44,29 @@ module Imyou
|
|
36
44
|
|
37
45
|
scope :partial_match_by_nickname, ->(nickname, with_name_column: true) do
|
38
46
|
if Gem::Version.new(ActiveRecord.version) >= Gem::Version.new(5)
|
39
|
-
records = self.
|
47
|
+
records = self.left_outer_joins(:imyou_nicknames).where(Imyou::Nickname.arel_table[:name].matches("%#{sanitize_sql_like(nickname)}%"))
|
40
48
|
unless name_column.nil? || with_name_column == false
|
41
|
-
records.or!(self.
|
49
|
+
records.or!(self.left_outer_joins(:imyou_nicknames).where(
|
42
50
|
self.arel_table[name_column].matches("%#{sanitize_sql_like(nickname)}%"))
|
43
51
|
)
|
44
52
|
end
|
45
53
|
else
|
54
|
+
joined_records = self.joins(<<~SQL
|
55
|
+
LEFT OUTER JOIN #{Imyou::Nickname.quoted_table_name}
|
56
|
+
ON
|
57
|
+
#{Imyou::Nickname.quoted_table_name}.#{connection.quote_column_name(:model_id)} = #{self.quoted_table_name}.#{connection.quote_column_name(:id)}
|
58
|
+
AND
|
59
|
+
#{Imyou::Nickname.quoted_table_name}.#{connection.quote_column_name(:model_type)} = #{connection.quote(self.name)}
|
60
|
+
SQL
|
61
|
+
)
|
46
62
|
arel_nickname_column = Imyou::Nickname.arel_table[:name]
|
47
63
|
records = if name_column.nil? || with_name_column == false
|
48
|
-
|
64
|
+
joined_records.where(
|
49
65
|
arel_nickname_column.matches("%#{sanitize_sql_like(nickname)}%")
|
50
66
|
)
|
51
67
|
else
|
52
68
|
arel_name_column = self.arel_table[name_column]
|
53
|
-
|
69
|
+
joined_records.where(
|
54
70
|
arel_nickname_column.matches("%#{sanitize_sql_like(nickname)}%").or(
|
55
71
|
arel_name_column.matches("%#{sanitize_sql_like(nickname)}%")
|
56
72
|
)
|
data/lib/imyou/version.rb
CHANGED