Class: Tomograph::ApiBlueprint::JsonSchema
- Inherits:
-
Object
- Object
- Tomograph::ApiBlueprint::JsonSchema
- Defined in:
- lib/tomograph/api_blueprint/json_schema.rb
Instance Method Summary collapse
-
#initialize(prefix, json_schema_path) ⇒ JsonSchema
constructor
A new instance of JsonSchema.
- #to_resources ⇒ Object
- #to_tomogram ⇒ Object
Constructor Details
#initialize(prefix, json_schema_path) ⇒ JsonSchema
Returns a new instance of JsonSchema.
6 7 8 9 |
# File 'lib/tomograph/api_blueprint/json_schema.rb', line 6 def initialize(prefix, json_schema_path) @prefix = prefix @documentation = JSON.parse(File.read(json_schema_path)) end |
Instance Method Details
#to_resources ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/tomograph/api_blueprint/json_schema.rb', line 24 def to_resources return @to_resources if @to_resources @to_resources = @documentation.group_by { |action| action['resource'] } @to_resources = @to_resources.each_with_object({}) do |(resource, actions), resource_map| requests = actions.map do |action| "#{action['method']} #{@prefix}#{action['path']}" end resource_map[resource] = requests end end |
#to_tomogram ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/tomograph/api_blueprint/json_schema.rb', line 11 def to_tomogram @tomogram ||= @documentation.inject([]) do |result, action| result.push(Tomograph::Tomogram::Action.new( path: "#{@prefix}#{action['path']}", method: action['method'], content_type: action['content-type'], requests: action['requests'], responses: action['responses'], resource: action['resource'] )) end end |