activerecord-bixformer 0.4.5 → 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 975aa8d7deb6a1db994d840cef88a84548505449
4
- data.tar.gz: 18b1ef10ebe9d3a1973468ff4de5899769db39e6
3
+ metadata.gz: ebdeb4d0ee7e10859c4a8d348ebcc505bf286d19
4
+ data.tar.gz: 805e0d16206bd0b33fad2e78dd412a3c300541d9
5
5
  SHA512:
6
- metadata.gz: 0e29358781db9fc618679e1f82816bcdfbbb91527df9a19037058f2ae0bb4007744b97151b0a9a7b76cf0d5c45e2bcfd105a81e8da246b74dfea21b45f864b68
7
- data.tar.gz: ecc108217d93c7c574d2df66f143e45ed905abe266772ebc6f11358784625fa4dc41008652edf67e5f7ca3a2501e26f199a7ea7885710e09b492a059d8e70286
6
+ metadata.gz: 8b179a6a9c55b795c791fdb8e746d9b05e772f32dbd2f3241d52da8e36c96e2945b011eb38fe9309a5410e341e0bd46989c4165144f43882142dae3da980c318
7
+ data.tar.gz: 41e2e7330629c0d28fd899e587a3bf0264e128d1c23b9d48f1fb3bdbc5dafa1a8e5a1a3995f3e83bfc15f06b99209d7a007cebfbcd40e61d365f05338a8af766
@@ -39,10 +39,10 @@ module ActiveRecord
39
39
  def import(value)
40
40
  return nil unless value.present?
41
41
 
42
- parser = @options[:parser]
43
- find_by = @options[:find_by] || :find_by
44
- scope = @options[:scope] || :all
45
- creator = @options[:creator] || :save
42
+ parser = @options[:parser]
43
+ find_by = @options[:find_by]
44
+ scope = @options[:scope] || :all
45
+ creator = @options[:creator] || :save
46
46
 
47
47
  condition = if parser.is_a?(::Proc)
48
48
  parser.call(value)
@@ -60,8 +60,14 @@ module ActiveRecord
60
60
 
61
61
  foreign_record = if find_by.is_a?(::Proc)
62
62
  find_by.call(scoped_relation, condition)
63
- else
63
+ elsif find_by
64
64
  scoped_relation.__send__(find_by, condition)
65
+ elsif scoped_relation.respond_to?(:find_by)
66
+ scoped_relation.find_by(condition)
67
+ else
68
+ scoped_relation.find do |r|
69
+ condition.all? { |k, v| r.__send__(k) == v rescue false }
70
+ end
65
71
  end
66
72
 
67
73
  if ! foreign_record && @options[:create]
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module Bixformer
3
- VERSION = "0.4.5"
3
+ VERSION = "0.4.6"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-bixformer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroaki Otsu