tomograph 2.3.0 → 2.4.0

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: 72667f1617b3f8b16e2c237632c8b90055da3f8a
4
- data.tar.gz: 8afa64e08a53277018cd9369b4d6d1e1aaf74a2e
3
+ metadata.gz: 68dab30fa771c79b9648e319ced4bd2264ba4d71
4
+ data.tar.gz: a5d4bf4ca5be0c68fcbdb2bf38d092206ad09798
5
5
  SHA512:
6
- metadata.gz: 405ae4d521121f17e3ddfa7fe5a11872507db656c2f8432694e9c36ff3282421f52c62682c51c91b34069db0e87a6df9aee99125f0f0f56f230ef730073e83df
7
- data.tar.gz: 63b54fc46fdda347372b85405a85a66789296a6f11da63bd913d89a6900ab3bfd853b0b93ec5b6d304b7bfd82163482890ff998f3882da115d61a7083821cd4e
6
+ metadata.gz: bb450d6411f3ea0afc48bd46eab99bef42de95c0f83c1864d1616f348e8ad577ec6e4f33b414e2eba16a06d6cb5a82a56beb17fe0be5921d4c9c8113b936330e
7
+ data.tar.gz: 625cacbfcd9489612496aa2e1f594f860648301924df7bca407a27a2c00ededac727a336c780a6c2ef36cf64c76e3ef5ab40805b215cb81416ceb88141c26768
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Change log
2
2
 
3
+ ### 2.4.0 - 2018-11-9
4
+
5
+ * features
6
+ * add '--split' option for command-line tool
7
+
3
8
  ### 2.3.0 - 2018-09-27
4
9
 
5
10
  * features
data/README.md CHANGED
@@ -1,12 +1,9 @@
1
- # Tomograph
1
+ # Tomograph [![Build Status](https://travis-ci.org/funbox/tomograph.svg?branch=master)](https://travis-ci.org/funbox/tomograph) [![Gem Version](https://badge.fury.io/rb/tomograph.svg)](https://badge.fury.io/rb/tomograph)
2
2
 
3
3
  <a href="https://funbox.ru">
4
4
  <img src="https://funbox.ru/badges/sponsored_by_funbox_compact.svg" alt="Sponsored by FunBox" width=250 />
5
5
  </a>
6
6
 
7
- [![Gem Version](https://badge.fury.io/rb/tomograph.svg)](https://badge.fury.io/rb/tomograph)
8
- [![Build Status](https://travis-ci.org/funbox/tomograph.svg?branch=master)](https://travis-ci.org/funbox/tomograph)
9
-
10
7
  Convert API Blueprint to JSON Schema and search.
11
8
 
12
9
  ## Installation
@@ -54,7 +51,7 @@ tomogram.to_json
54
51
  ```
55
52
 
56
53
  Example input:
57
- ```
54
+ ```apib
58
55
  FORMAT: 1A
59
56
  HOST: http://test.local
60
57
 
@@ -96,7 +93,7 @@ Project
96
93
  ```
97
94
 
98
95
  Example output:
99
- ```
96
+ ```json
100
97
  [
101
98
  {
102
99
  "path": "/sessions",
data/exe/tomograph CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'fileutils'
4
+
3
5
  require 'methadone'
4
6
 
5
7
  require 'tomograph'
@@ -12,9 +14,10 @@ include Methadone::CLILogging
12
14
  version Tomograph::VERSION
13
15
  description 'Converts API Blueprint to JSON Schema'
14
16
  on('-f INPUT_FORMAT', '--format', 'Force input format: "apib" or "yaml". Default: detect by file extension.')
15
- arg :input, 'path/to/doc.apib (API Blueprint) or path/to/doc.yaml (API Elements)'
16
- arg :output, 'path/to/doc.json'
17
17
  on('--exclude-description', 'Exclude "description" keys.')
18
+ on('--split', 'Split output into files by method.')
19
+ arg :input, 'path/to/doc.apib (API Blueprint) or path/to/doc.yaml (API Elements)'
20
+ arg :output, 'path/to/doc.json or path/to/dir if --split is used.'
18
21
 
19
22
  def prune!(obj, unwanted_key)
20
23
  if obj.is_a?(Hash)
@@ -25,43 +28,63 @@ def prune!(obj, unwanted_key)
25
28
  end
26
29
  end
27
30
 
31
+ def guess_format(opt_format, input)
32
+ case opt_format && opt_format.downcase
33
+ when 'apib'
34
+ :apib
35
+ when 'yaml'
36
+ :yaml
37
+ when nil
38
+ case File.extname(input).downcase
39
+ when '.apib'
40
+ :apib
41
+ when '.yaml', '.yml'
42
+ :yaml
43
+ else
44
+ fail 'Unsupported input file extension!'
45
+ end
46
+ else
47
+ fail 'Unsupported input format!'
48
+ end
49
+ end
50
+
51
+ def write_split_json(actions, output)
52
+ FileUtils.mkdir_p(output)
53
+ actions.clone.each do |action|
54
+ json_name = "#{action.delete("path").to_s} #{action.delete("method")}".gsub('/', ':') +
55
+ '.json'
56
+ write_json(action, File.join(output, json_name))
57
+ end
58
+ end
59
+
60
+ def write_json(obj, path)
61
+ json = MultiJson.dump(obj, pretty: true)
62
+ File.open(path, 'w') do |file|
63
+ file.write(json)
64
+ end
65
+ end
66
+
28
67
  main do |input, output|
29
- opt_format = options['format']
30
- format = case opt_format && opt_format.downcase
31
- when 'apib'
32
- :apib
33
- when 'yaml'
34
- :yaml
35
- when nil
36
- case File.extname(input).downcase
37
- when '.apib'
38
- :apib
39
- when '.yaml'
40
- :yaml
41
- else
42
- fail 'Unsupported input file extension!'
43
- end
44
- else
45
- fail 'Unsupported input format!'
46
- end
68
+ format = guess_format(options['format'], input)
47
69
  format_key = case format
48
70
  when :apib
49
71
  :apib_path
50
72
  when :yaml
51
73
  :drafter_yaml_path
52
74
  else
53
- fail 'Unimplemented!'
75
+ fail NotImplementedError
54
76
  end
55
- tomogram = Tomograph::Tomogram.new({format_key => input})
56
- json = if options['exclude-description']
57
- actions = tomogram.to_a.map(&:to_hash)
58
- prune!(actions, 'description')
59
- MultiJson.dump(actions, pretty: true)
60
- else
61
- tomogram.to_json
62
- end
63
- File.open(output, 'w') do |file|
64
- file.write(json)
77
+ tomogram = Tomograph::Tomogram.new(format_key => input)
78
+ actions = tomogram.to_a.map(&:to_hash)
79
+
80
+ if options['exclude-description']
81
+ prune!(actions, 'description')
82
+ end
83
+
84
+ if options['split']
85
+ write_split_json(actions, output)
86
+ else
87
+ write_json(actions, output)
65
88
  end
66
89
  0
67
90
  end
@@ -1,3 +1,3 @@
1
1
  module Tomograph
2
- VERSION = '2.3.0'.freeze
2
+ VERSION = '2.4.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tomograph
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - d.efimov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-27 00:00:00.000000000 Z
11
+ date: 2018-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: methadone