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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 25adebb4c4bd3d882502f7cf737a510e269037e66b0d99739b708006558b45e3
4
- data.tar.gz: bd3b45051b198b474f8d741d78404ebbbb89acb215afe188655a7bfe8be4df44
3
+ metadata.gz: 437f6453c5c674668419f8f5968eeb9d14836e4dac03b0894cf64c9b0f73fee4
4
+ data.tar.gz: 892461025e8a962f5d4738a10d56f768c3a2ed53dcf1641a53acc8ce9b6afd58
5
5
  SHA512:
6
- metadata.gz: 96311348b980c930e1d4c94020a9ff8cec6d7a77c5abf263c015d7479bc70c69f06c2194e987a279021662564a0ba81e310183b6c024edfb7cc3ca9fd07b8cbd
7
- data.tar.gz: 0b0bbaaaf2e240a6f78007e30f189fb4e3cddc38c3110e56912fa44de3350db927b48e4b3d155c30807e63552da2f30a13ee492de39447f31ea670d571d73567
6
+ metadata.gz: ad812533dff9b9265d46ef784f65c9f3035f8ddca8742ac3c02755e8c976bc408e7c64e49511135c03731c87d4f30e41520d85c46214d339178c3a8531c9e858
7
+ data.tar.gz: 360976116e0941de8f7d5e848096bf17bcc733aa0d0de20e4a256883da665e0ea0cd44d50e63d931962629b9d2b193defbc93cbe1f7fc15cbaa7c58d58a4f634
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- imyou (1.0.0)
4
+ imyou (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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
- with_nicknames.merge(
15
- Imyou::Nickname.where(Imyou::Nickname.arel_table[:name].eq(sanitize_sql_like(nickname)))
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
- with_nicknames.merge(
21
- Imyou::Nickname.where(Imyou::Nickname.arel_table[:name].matches("%#{sanitize_sql_like(nickname)}%"))
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?
@@ -1,3 +1,3 @@
1
1
  module Imyou
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.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.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - patorash