activerecord-bixformer 0.4.3 → 0.4.4
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7fb89bcee1a68dc2fa2dc3b9be84e4d5720ff8db
|
4
|
+
data.tar.gz: 397f458b9bb776d27f195b0a702905b1cb0506d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96adb2970166144d0b9990a6d87e86a644f323f1f45450addb342a98c16631bc84091cd82bfb11a9b044e8a898d30384dd8cc0d3830ada53e1d1e61ecdb106d3
|
7
|
+
data.tar.gz: e629bb57d0c732495c8ecc304fa2a34f4c658918665dfbba4074b2566cd317190e7d57f36d4d67a0de3b167bec0b7ac85c502a962e6eb5c7cea0586b034985ff
|
@@ -5,16 +5,16 @@ module ActiveRecord
|
|
5
5
|
def initialize(model, attribute_name, options)
|
6
6
|
super
|
7
7
|
|
8
|
-
unless @options[:
|
9
|
-
raise ArgumentError.new 'Not configured required options :
|
8
|
+
unless @options[:formatter]
|
9
|
+
raise ArgumentError.new 'Not configured required options : formatter'
|
10
10
|
end
|
11
11
|
|
12
|
-
@options[:
|
13
|
-
|
14
|
-
|
12
|
+
@options[:parser] ||= if @options[:formatter].is_a?(::String) || @options[:formatter].is_a?(::Symbol)
|
13
|
+
-> (v) { { @options[:formatter] => v } }
|
14
|
+
end
|
15
15
|
|
16
|
-
unless @options[:
|
17
|
-
raise ArgumentError.new 'Not configured required options :
|
16
|
+
unless @options[:parser]
|
17
|
+
raise ArgumentError.new 'Not configured required options : parser'
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -27,7 +27,7 @@ module ActiveRecord
|
|
27
27
|
|
28
28
|
return nil unless foreign_record
|
29
29
|
|
30
|
-
formatter = @options[:
|
30
|
+
formatter = @options[:formatter]
|
31
31
|
|
32
32
|
if formatter.is_a?(::Proc)
|
33
33
|
formatter.call(foreign_record)
|
@@ -39,31 +39,33 @@ module ActiveRecord
|
|
39
39
|
def import(value)
|
40
40
|
return nil unless value.present?
|
41
41
|
|
42
|
-
|
42
|
+
parser = @options[:parser]
|
43
|
+
find_by = @options[:find_by] || :find_by
|
43
44
|
scope = @options[:scope] || :all
|
44
|
-
finder = @options[:finder] || :find_by
|
45
45
|
creator = @options[:creator] || :save
|
46
46
|
|
47
|
-
condition = if
|
48
|
-
|
47
|
+
condition = if parser.is_a?(::Proc)
|
48
|
+
parser.call(value)
|
49
49
|
else
|
50
|
-
|
50
|
+
foreign_constant.__send__(parser, value)
|
51
51
|
end
|
52
52
|
|
53
53
|
return nil unless condition
|
54
54
|
|
55
|
-
|
56
|
-
|
55
|
+
scoped_relation = if scope.is_a?(::Proc)
|
56
|
+
scope.call
|
57
|
+
else
|
58
|
+
foreign_constant.__send__(scope)
|
59
|
+
end
|
60
|
+
|
61
|
+
foreign_record = if find_by.is_a?(::Proc)
|
62
|
+
find_by.call(scoped_relation, condition)
|
57
63
|
else
|
58
|
-
|
64
|
+
scoped_relation.__send__(find_by, condition)
|
59
65
|
end
|
60
66
|
|
61
67
|
if ! foreign_record && @options[:create]
|
62
|
-
foreign_record =
|
63
|
-
scope.call.build(condition)
|
64
|
-
else
|
65
|
-
foreign_constant.__send__(scope).build(condition)
|
66
|
-
end
|
68
|
+
foreign_record = scoped_relation.build(condition)
|
67
69
|
|
68
70
|
if creator.is_a?(::Proc)
|
69
71
|
creator.call(foreign_record)
|