class Tomograph::ApiBlueprint::Drafter4::Yaml
Public Class Methods
new(prefix, drafter_yaml_path)
click to toggle source
# File lib/tomograph/api_blueprint/drafter_4/yaml.rb, line 9 def initialize(prefix, drafter_yaml_path) @prefix = prefix @documentation = YAML.safe_load(File.read(drafter_yaml_path)) end
Public Instance Methods
action?(content)
click to toggle source
# File lib/tomograph/api_blueprint/drafter_4/yaml.rb, line 83 def action?(content) content['element'] == 'httpTransaction' end
action_hash(related_actions)
click to toggle source
# File lib/tomograph/api_blueprint/drafter_4/yaml.rb, line 95 def action_hash(related_actions) { path: "#{@prefix}#{related_actions.first.path}", method: related_actions.first.method, content_type: related_actions.first.content_type, requests: related_actions.map(&:request).flatten.uniq, responses: related_actions.map(&:responses).flatten.uniq, resource: related_actions.first.resource } end
actions()
click to toggle source
# File lib/tomograph/api_blueprint/drafter_4/yaml.rb, line 87 def actions @actions ||= without_group_actions .flatten .group_by { |action| "#{action.method} #{action.path}" }.map do |_key, related_actions| action_hash(related_actions) end.flatten end
group?(group)
click to toggle source
# File lib/tomograph/api_blueprint/drafter_4/yaml.rb, line 25 def group?(group) return false if group['element'] == 'resource' group['element'] != 'copy' && # Element is a human readable text group['meta']['classes']['content'][0]['content'] == 'resourceGroup' # skip Data Structures end
groups()
click to toggle source
# File lib/tomograph/api_blueprint/drafter_4/yaml.rb, line 14 def groups @groups ||= @documentation['content'][0]['content'].each_with_object([]) do |group, result_groups| result_groups.push(group) if group?(group) result_groups.push('content' => [group]) if single_resource?(group) end end
resource?(resource)
click to toggle source
# File lib/tomograph/api_blueprint/drafter_4/yaml.rb, line 39 def resource?(resource) resource['element'] != 'copy' # Element is a human readable text end
resource_path(resource)
click to toggle source
# File lib/tomograph/api_blueprint/drafter_4/yaml.rb, line 43 def resource_path(resource) resource['attributes'] && resource['attributes']['href']['content'] end
resources()
click to toggle source
# File lib/tomograph/api_blueprint/drafter_4/yaml.rb, line 31 def resources @resources ||= groups.inject([]) do |result_groups, group| result_groups.push(group['content'].each_with_object([]) do |resource, result_resources| result_resources.push('resource' => resource, 'resource_path' => resource_path(resource)) if resource?(resource) end) end.flatten end
single_resource?(group)
click to toggle source
# File lib/tomograph/api_blueprint/drafter_4/yaml.rb, line 21 def single_resource?(group) group['element'] == 'resource' end
to_resources()
click to toggle source
# File lib/tomograph/api_blueprint/drafter_4/yaml.rb, line 112 def to_resources return @to_resources if @to_resources @to_resources = actions.group_by { |action| action[:resource] } @to_resources = @to_resources.inject({}) do |res, related_actions| requests = related_actions[1].map do |action| "#{action[:method]} #{action[:path]}" end res.merge(related_actions[1].first[:resource] => requests) end end
to_tomogram()
click to toggle source
# File lib/tomograph/api_blueprint/drafter_4/yaml.rb, line 106 def to_tomogram @tomogram ||= actions.inject([]) do |result, action| result.push(Tomograph::Tomogram::Action.new(**action)) end end
transition?(transition)
click to toggle source
# File lib/tomograph/api_blueprint/drafter_4/yaml.rb, line 55 def transition?(transition) transition['element'] == 'transition' end
transition_hash(transition, resource)
click to toggle source
# File lib/tomograph/api_blueprint/drafter_4/yaml.rb, line 59 def transition_hash(transition, resource) { 'transition' => transition, 'transition_path' => transition_path(transition, resource['resource_path']), 'resource' => resource['resource_path'] } end
transition_path(transition, resource_path)
click to toggle source
# File lib/tomograph/api_blueprint/drafter_4/yaml.rb, line 67 def transition_path(transition, resource_path) transition['attributes'] && transition['attributes']['href']['content'] || resource_path end
transitions()
click to toggle source
# File lib/tomograph/api_blueprint/drafter_4/yaml.rb, line 47 def transitions @transitions ||= resources.inject([]) do |result_resources, resource| result_resources.push(resource['resource']['content'].each_with_object([]) do |transition, result_transitions| result_transitions.push(transition_hash(transition, resource)) if transition?(transition) end) end.flatten end
without_group_actions()
click to toggle source
# File lib/tomograph/api_blueprint/drafter_4/yaml.rb, line 71 def without_group_actions transitions.inject([]) do |result_transition, transition| result_transition.push(transition['transition']['content'].each_with_object([]) do |content, result_contents| result_contents.push(Tomograph::ApiBlueprint::Drafter4::Yaml::Action.new( content['content'], transition['transition_path'], transition['resource'] )) if action?(content) end) end end