tomograph 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee14aba11b9ba06a3a83fbe84055570c888cb013
4
- data.tar.gz: 0f364c057b8f2569deb21397db74cbb13eb3fe0e
3
+ metadata.gz: 2eff2a08ebfda01a96b162d0fcad6204d7f17a79
4
+ data.tar.gz: 6845001d37330abad0d9205ed403c2113cc3e364
5
5
  SHA512:
6
- metadata.gz: 18d05e492cca9fa7de92a32b564f926842457a1351125beb293d078f8e3d3022503cb8194ef0b0f2b3f6ea4381722871e70cee9fe3eab149b2c031f90157969b
7
- data.tar.gz: 36cb8b49d448f23c08c814c0a0a2bd83a2c84f5c4a347892b543622bcc71563bcea4c364015c87f275f624bc259161e981554c69e8faf0a63a2abfa86c1dd933
6
+ metadata.gz: 7fc61193b71d90e5519a7c3700abb0dd6eabc92f7b8ef09c099352bec752308226d772b4e6034d784c1fb354014ba1801c436510816e95e471271a5f017c2739
7
+ data.tar.gz: 0624d441d088e33e4a08f136eeb2c37bd35cda4d4ff00416ab4600521715329aa9ab0d08ddcb581c3c56ae4ef105a7430636301575591d3ec353e0a429e9c631
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ # Change log
2
+
3
+ ### 1.1.0 - 2017-06-15
4
+
5
+ * features
6
+ * hash resource with request
data/README.md CHANGED
@@ -190,6 +190,16 @@ Path to API Blueprint documentation pre-parsed with `drafter` and saved to a YAM
190
190
 
191
191
  Default empty String. Prefix of API requests. Example: `'/api'`.
192
192
 
193
+ ### to_resources
194
+
195
+ Hash resource with requests.
196
+ The result for the example above:
197
+ ```ruby
198
+ {
199
+ '/sessions' => ['POST /sessions']
200
+ }
201
+ ```
202
+
193
203
  ## License
194
204
 
195
205
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -46,8 +46,7 @@ module Tomograph
46
46
  @transitions ||= resources.inject([]) do |result_resources, resource|
47
47
  result_resources.push(resource['resource']['content'].inject([]) do |result_transitions, transition|
48
48
  next result_transitions unless transition?(transition)
49
- result_transitions.push('transition' => transition,
50
- 'transition_path' => transition_path(transition, resource['resource_path']))
49
+ result_transitions.push(transition_hash(transition, resource))
51
50
  end)
52
51
  end.flatten
53
52
  end
@@ -56,31 +55,69 @@ module Tomograph
56
55
  transition['element'] == 'transition'
57
56
  end
58
57
 
58
+ def transition_hash(transition, resource)
59
+ {
60
+ 'transition' => transition,
61
+ 'transition_path' => transition_path(transition, resource['resource_path']),
62
+ 'resource' => resource['resource_path']
63
+ }
64
+ end
65
+
59
66
  def transition_path(transition, resource_path)
60
67
  transition['attributes'] && transition['attributes']['href'] || resource_path
61
68
  end
62
69
 
63
- def actions
64
- @actions ||= transitions.inject([]) do |result_transition, transition|
70
+ def without_group_actions
71
+ transitions.inject([]) do |result_transition, transition|
65
72
  result_transition.push(transition['transition']['content'].inject([]) do |result_contents, content|
66
73
  next result_contents unless action?(content)
67
74
  result_contents.push(Tomograph::ApiBlueprint::Yaml::Action.new(
68
- content['content'], transition['transition_path']
75
+ content['content'],
76
+ transition['transition_path'],
77
+ transition['resource']
69
78
  ))
70
79
  end)
71
- end.flatten
80
+ end
72
81
  end
73
82
 
74
83
  def action?(content)
75
84
  content['element'] == 'httpTransaction'
76
85
  end
77
86
 
87
+ def actions
88
+ @actions ||= without_group_actions
89
+ .flatten
90
+ .group_by { |action| "#{action.method} #{action.path}" }.map do |_key, related_actions|
91
+ action_hash(related_actions)
92
+ end.flatten
93
+ end
94
+
95
+ def action_hash(related_actions)
96
+ {
97
+ path: "#{@prefix}#{related_actions.first.path}",
98
+ method: related_actions.first.method,
99
+ request: related_actions.first.request,
100
+ responses: related_actions.map(&:responses).flatten,
101
+ resource: related_actions.first.resource
102
+ }
103
+ end
104
+
78
105
  def to_tomogram
79
- @tomogram ||= Tomograph::Tomogram::Action.merge(
80
- actions.inject([]) do |result, action|
81
- result.push(action.to_tomogram.add_prefix(@prefix))
106
+ @tomogram ||= actions.inject([]) do |result, action|
107
+ result.push(Tomograph::Tomogram::Action.new(action))
108
+ end
109
+ end
110
+
111
+ def to_resources
112
+ return @to_resources if @to_resources
113
+
114
+ @to_resources = actions.group_by { |action| action[:resource] }
115
+ @to_resources = @to_resources.inject({}) do |res, related_actions|
116
+ requests = related_actions[1].map do |action|
117
+ "#{action[:method]} #{action[:path]}"
82
118
  end
83
- )
119
+ res.merge(related_actions[1].first[:resource] => requests)
120
+ end
84
121
  end
85
122
  end
86
123
  end
@@ -4,12 +4,13 @@ module Tomograph
4
4
  module ApiBlueprint
5
5
  class Yaml
6
6
  class Action
7
- def initialize(content, path)
7
+ def initialize(content, path, resource)
8
8
  @content = content
9
9
  @path = path
10
+ @resource = resource
10
11
  end
11
12
 
12
- attr_reader :path
13
+ attr_reader :path, :resource
13
14
 
14
15
  def method
15
16
  @method ||= @content.first['attributes']['method']
@@ -47,12 +48,6 @@ module Tomograph
47
48
  }
48
49
  end
49
50
  end
50
-
51
- def to_tomogram
52
- Tomograph::Tomogram::Action.new(
53
- path: path, method: method, request: request, responses: responses
54
- )
55
- end
56
51
  end
57
52
  end
58
53
  end
@@ -24,5 +24,9 @@ module Tomograph
24
24
  action.method == method && action.path.match(path)
25
25
  end
26
26
  end
27
+
28
+ def to_resources
29
+ @documentation.to_resources
30
+ end
27
31
  end
28
32
  end
@@ -5,27 +5,12 @@ module Tomograph
5
5
  class Action
6
6
  attr_reader :path, :method, :request, :responses
7
7
 
8
- def initialize(path:, method:, request:, responses:)
8
+ def initialize(path:, method:, request:, responses:, resource:)
9
9
  @path ||= Tomograph::Path.new(path)
10
10
  @method ||= method
11
11
  @request ||= request
12
12
  @responses ||= responses
13
- end
14
-
15
- def self.merge(actions)
16
- actions.group_by { |action| "#{action.method} #{action.path}" }.map do |_key, related_actions|
17
- new(
18
- path: related_actions.first.path.to_s,
19
- method: related_actions.first.method,
20
- request: related_actions.first.request,
21
- responses: related_actions.map(&:responses).flatten
22
- )
23
- end.flatten
24
- end
25
-
26
- def add_prefix(prefix)
27
- @path = Tomograph::Path.new("#{prefix}#{path}")
28
- self
13
+ @resource ||= resource
29
14
  end
30
15
 
31
16
  def find_responses(status:)
@@ -1,3 +1,3 @@
1
1
  module Tomograph
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.1.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: 1.0.0
4
+ version: 1.1.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: 2017-04-20 00:00:00.000000000 Z
11
+ date: 2017-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -147,6 +147,7 @@ extra_rdoc_files: []
147
147
  files:
148
148
  - ".gitignore"
149
149
  - ".rubocop.yml"
150
+ - CHANGELOG.md
150
151
  - CODE_OF_CONDUCT.md
151
152
  - Gemfile
152
153
  - LICENSE.txt