declarative_mapper 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/csv_parser.rb +19 -22
- data/lib/declarative_mapper.rb +1 -1
- data/lib/module_helper.rb +19 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10539dff30e5685fc48c7e114d864b099287be1887103b1f973d406c0bbdb728
|
4
|
+
data.tar.gz: dd743aabb3b023f133de96501dc3c22bfbd5961356366ee91dc2dbf3938e73c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 996424166a6534124e4a6ef57f3f14499f278a2c3283d55bac6fe8f20b18df9df5349c5a2ff6d9012b3865fc5d0e591388a680a043b89eb09e2514ff70fe33aa
|
7
|
+
data.tar.gz: b38785bfddf2bcd24209834a7e6c7987fae3d57e5ae1901a898c8246c24958b676119835d98e7ef1a67cdd518c7a18597eb3e6079af88d82eda832a40961ef28
|
data/lib/csv_parser.rb
CHANGED
@@ -19,37 +19,34 @@ class CSVParser
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def parse(csv_row)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
22
|
+
ModuleHelper.deep_transform_values_with_path(mapping_hash) do |csv_field_name, path|
|
23
|
+
field_name = path.last
|
24
|
+
|
25
|
+
if ModuleHelper.needs_method?(csv_field_name)
|
26
|
+
parsed_signature =
|
27
|
+
ModuleHelper.parse_signature(csv_field_name, client_name, table_name, field_name)
|
28
|
+
|
29
|
+
args = argument_values(parsed_signature[:arguments], csv_row)
|
30
|
+
|
31
|
+
call_shared_or_client_method(
|
32
|
+
parsed_signature[:path] + path[0..-2],
|
33
|
+
parsed_signature[:method_name],
|
34
|
+
*args
|
35
|
+
)
|
36
|
+
else
|
37
|
+
csv_row[csv_field_name]
|
38
|
+
end
|
40
39
|
end
|
41
|
-
|
42
|
-
result.symbolize_keys
|
43
40
|
end
|
44
41
|
|
45
42
|
private
|
46
43
|
|
47
|
-
def
|
44
|
+
def mapping_hash
|
48
45
|
yml[:mapping]
|
49
46
|
end
|
50
47
|
|
51
48
|
def call_shared_or_client_method(path, method_name, *args)
|
52
|
-
path.map(&:camelize).join('::').constantize.send(method_name, *args)
|
49
|
+
path.map(&:to_s).map(&:camelize).join('::').constantize.send(method_name, *args)
|
53
50
|
end
|
54
51
|
|
55
52
|
def argument_values(argument_names, csv_row)
|
data/lib/declarative_mapper.rb
CHANGED
@@ -33,7 +33,7 @@ class DeclarativeMapper
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def require_client_mapper_methods
|
36
|
-
Dir["#{client_mapper_methods_dir_path}
|
36
|
+
Dir["#{client_mapper_methods_dir_path}/**/*.rb"].each { |file| require file }
|
37
37
|
end
|
38
38
|
|
39
39
|
def require_shared_mapper_methods
|
data/lib/module_helper.rb
CHANGED
@@ -30,4 +30,23 @@ module ModuleHelper
|
|
30
30
|
def self.needs_method?(signature)
|
31
31
|
!!(signature =~ /\(.*\)/)
|
32
32
|
end
|
33
|
+
|
34
|
+
# Example of usage:
|
35
|
+
#
|
36
|
+
# my_hash = {a: 0, b: {c: 1, d: 2, e: {f: 3}}}
|
37
|
+
# values = %w(mother washed the ceiling)
|
38
|
+
#
|
39
|
+
# result = deep_transform_values_with_path(my_hash) do |value, path|
|
40
|
+
# path.join('/') + '/' + values[value]
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# {:a=>"a/mother", :b=>{:c=>"b/c/washed", :d=>"b/d/the", :e=>{:f=>"b/e/f/ceiling"}}}
|
44
|
+
#
|
45
|
+
def self.deep_transform_values_with_path(object, path=[], &block)
|
46
|
+
return yield(object, path) unless object.is_a?(Hash)
|
47
|
+
|
48
|
+
object.map do |key, value|
|
49
|
+
[key, deep_transform_values_with_path(value, path + [key], &block)]
|
50
|
+
end.to_h
|
51
|
+
end
|
33
52
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: declarative_mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Nemytchenko
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-12-
|
12
|
+
date: 2019-12-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|