schema-model 0.5.3 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/schema-json2csv +13 -5
- data/lib/schema/model.rb +5 -0
- data/schema-model.gemspec +1 -1
- 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: af3929b906f207f3854237cc8d3e3011d3829d82c1783767911572847d585dab
|
4
|
+
data.tar.gz: c9d2a9dd70152da1090d00b13d701bbf3da41221798d0503e07d5736b73b9564
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c6841aa7565e1d74757d6262f39556e8609fcb44ec27e999530834e6c69e7c50e445aac7c3fb4bc8097b4eb3bda2997f0613631160740a6c11747b640f5be08
|
7
|
+
data.tar.gz: 46392386e8997ac7bf9478bc74371938f8f5cca1e8f710fcebc71c381dbda2a189717b6b67cfd634974cf31f17e8632ac99e60c17467a058eb74702053ee7df7
|
data/bin/schema-json2csv
CHANGED
@@ -41,6 +41,7 @@ raise("file #{options[:require_file]} not found") unless require(options[:requir
|
|
41
41
|
raise("schema #{options[:schema_class_name]} not found") unless Object.const_defined?(options[:schema_class_name])
|
42
42
|
|
43
43
|
schema_class = Object.const_get(options[:schema_class_name])
|
44
|
+
schema_class.schema_include Schema::Arrays
|
44
45
|
|
45
46
|
json_data =
|
46
47
|
if options[:json_file]
|
@@ -52,7 +53,13 @@ json_data =
|
|
52
53
|
raise('no json data specified')
|
53
54
|
end
|
54
55
|
|
55
|
-
schema
|
56
|
+
def output_csv(schema, io)
|
57
|
+
str = CSV.generate do |csv|
|
58
|
+
csv << schema.to_a.flatten
|
59
|
+
end
|
60
|
+
|
61
|
+
io.print str
|
62
|
+
end
|
56
63
|
|
57
64
|
io =
|
58
65
|
if file = options[:csv_file]
|
@@ -70,8 +77,9 @@ io =
|
|
70
77
|
$stdout
|
71
78
|
end
|
72
79
|
|
73
|
-
|
74
|
-
|
75
|
-
end
|
80
|
+
json_data = JSON.parse(json_data)
|
81
|
+
json_data = [json_data] unless json_data.is_a?(Array)
|
76
82
|
|
77
|
-
|
83
|
+
json_data.each do |data|
|
84
|
+
output_csv(schema_class.from_hash(data), io)
|
85
|
+
end
|
data/lib/schema/model.rb
CHANGED
@@ -67,6 +67,11 @@ module Schema
|
|
67
67
|
config[:schema_includes] = config[:schema_includes] + [mod]
|
68
68
|
redefine_class_method(:schema_config, config.freeze)
|
69
69
|
include mod
|
70
|
+
schema.values.each do |field_options|
|
71
|
+
next unless field_options[:association]
|
72
|
+
|
73
|
+
const_get(field_options[:class_name]).schema_include(mod)
|
74
|
+
end
|
70
75
|
end
|
71
76
|
|
72
77
|
def add_attribute_methods(name, options)
|
data/schema-model.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Doug Youch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: inheritance-helper
|