Class: Tomograph::Tomogram
- Inherits:
-
Object
- Object
- Tomograph::Tomogram
- Extended by:
- Gem::Deprecate
- Defined in:
- lib/tomograph/tomogram.rb,
lib/tomograph/tomogram/action.rb
Defined Under Namespace
Classes: Action
Instance Method Summary collapse
- #find_request(method:, path:) ⇒ Object
- #find_request_with_content_type(method:, path:, content_type:) ⇒ Object
-
#initialize(prefix: '', drafter_yaml_path: nil, tomogram_json_path: nil, crafter_yaml_path: nil, openapi2_json_path: nil, openapi3_yaml_path: nil) ⇒ Tomogram
constructor
A new instance of Tomogram.
- #prefix_match?(raw_path) ⇒ Boolean
- #to_a ⇒ Object
- #to_json(*_args) ⇒ Object
- #to_resources ⇒ Object
Constructor Details
#initialize(prefix: '', drafter_yaml_path: nil, tomogram_json_path: nil, crafter_yaml_path: nil, openapi2_json_path: nil, openapi3_yaml_path: nil) ⇒ Tomogram
Returns a new instance of Tomogram.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/tomograph/tomogram.rb', line 13 def initialize(prefix: '', drafter_yaml_path: nil, tomogram_json_path: nil, crafter_yaml_path: nil, openapi2_json_path: nil, openapi3_yaml_path: nil) @documentation = if tomogram_json_path Tomograph::ApiBlueprint::JsonSchema.new(prefix, tomogram_json_path) elsif crafter_yaml_path Tomograph::ApiBlueprint::Crafter::Yaml.new(prefix, crafter_yaml_path) elsif openapi2_json_path Tomograph::OpenApi::OpenApi2.new(prefix, openapi2_json_path) elsif openapi3_yaml_path Tomograph::OpenApi::OpenApi3.new(prefix, openapi3_yaml_path) else Tomograph::ApiBlueprint::Drafter4::Yaml.new(prefix, drafter_yaml_path) end @prefix = prefix end |
Instance Method Details
#find_request(method:, path:) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/tomograph/tomogram.rb', line 41 def find_request(method:, path:) path = Tomograph::Path.new(path).to_s to_a.find do |action| action.method == method && action.path.match(path) end end |
#find_request_with_content_type(method:, path:, content_type:) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/tomograph/tomogram.rb', line 49 def find_request_with_content_type(method:, path:, content_type:) path = Tomograph::Path.new(path).to_s to_a.find do |action| action.method == method && action.path.match(path) && action.content_type == content_type end end |
#prefix_match?(raw_path) ⇒ Boolean
61 62 63 |
# File 'lib/tomograph/tomogram.rb', line 61 def prefix_match?(raw_path) raw_path.include?(@prefix) end |
#to_a ⇒ Object
33 34 35 |
# File 'lib/tomograph/tomogram.rb', line 33 def to_a @actions ||= @documentation.to_tomogram end |
#to_json(*_args) ⇒ Object
37 38 39 |
# File 'lib/tomograph/tomogram.rb', line 37 def to_json(*_args) JSON.pretty_generate(to_a.map(&:to_hash)) end |
#to_resources ⇒ Object
57 58 59 |
# File 'lib/tomograph/tomogram.rb', line 57 def to_resources @resources ||= @documentation.to_resources end |