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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3b38b29a742bf9ef15a2bda1ad322ef395971bd85a857134209ade3ace47deb
4
- data.tar.gz: 35c6ca2010311f274ce1ce34ac8c8dcd6b676b0d15079a4d740fafd12d1b8a73
3
+ metadata.gz: 2ea37cab3c8ce4f35113a47972b4936655a977040adee8ea2bd6b59f01ad5168
4
+ data.tar.gz: 7de5c7103f8e133355f0c08ad0fa6e7056e33c9101930c7326a965aa09083022
5
5
  SHA512:
6
- metadata.gz: dd48854d5bd7ede79785ede0e2738229e500225a4c61a3b9e0e119e43e2b4b8b45fb68c48a29271d50b8aceaf50d0794e3bf9463aa4da581f8d545e9eec39429
7
- data.tar.gz: be165ca2b9303be2664d647907f9b410c1b805227e9634ed75d6232a36281e54fabb7fb9af5e41c268c7b7d86c338699ca0b86ddab45bbeb6a9cf08949f0ba5c
6
+ metadata.gz: 1ddaf339b9c10bfb339280fd05eb4dc827b46ca6f163f3031a7e95e292ff8eea6624f5660f605f6ba3827f22a95bb60f8fc1348ec118843f3a2560059ca12861
7
+ data.tar.gz: 3f7a465be25dd666cab0aa6a3e427f9ed49b836f3329c3ab5ae96771a156b1e3334b5fd1d1ab9c445abdabcafa368bfe03ad435e07cea2fa6d94b182f5436dff
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- imyou (1.1.3)
4
+ imyou (1.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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, -> { eager_load(:imyou_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.with_nicknames.where(Imyou::Nickname.arel_table[:name].eq(nickname))
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.with_nicknames.where(name_column => nickname))
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
- self.with_nicknames.where(
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
- self.with_nicknames.where(
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.with_nicknames.where(Imyou::Nickname.arel_table[:name].matches("%#{sanitize_sql_like(nickname)}%"))
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.with_nicknames.where(
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
- self.with_nicknames.where(
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
- self.with_nicknames.where(
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
  )
@@ -1,3 +1,3 @@
1
1
  module Imyou
2
- VERSION = "1.1.3"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imyou
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - patorash