schema-model 0.5.3 → 0.5.5

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
  SHA256:
3
- metadata.gz: 886e2c37370ab33f380d853295e6e8036e697af0a29c7e7be2a045a9a70b44ad
4
- data.tar.gz: 95b80463a0a3f4b33126ed379750ae9aac7f0cc455a45f68ad0072579f0b7872
3
+ metadata.gz: af3929b906f207f3854237cc8d3e3011d3829d82c1783767911572847d585dab
4
+ data.tar.gz: c9d2a9dd70152da1090d00b13d701bbf3da41221798d0503e07d5736b73b9564
5
5
  SHA512:
6
- metadata.gz: 7b8ba2b50715578d71bf6452222935535876ce836e2d34583078e64cdc62fee980e7763d23c302290a5fb31547668fdb836e25a54f290e9c4530b7c8afed4db8
7
- data.tar.gz: 8475c78e34497236bbb5ee719ad632422701affa68539bc6bfdd5f508254dda8f0b4919100d949f767c932006005b6dae29a62b2a89f449ae58a918c3796ecce
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 = schema_class.from_hash(JSON.parse(json_data))
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
- str = CSV.generate do |csv|
74
- csv << schema.to_a.flatten
75
- end
80
+ json_data = JSON.parse(json_data)
81
+ json_data = [json_data] unless json_data.is_a?(Array)
76
82
 
77
- io.print str
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'schema-model'
5
- s.version = '0.5.3'
5
+ s.version = '0.5.5'
6
6
  s.licenses = ['MIT']
7
7
  s.summary = 'Schema Model'
8
8
  s.description = 'Easy way to create models from payloads'
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.3
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-21 00:00:00.000000000 Z
11
+ date: 2019-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inheritance-helper