Class: Tomograph::Tomogram

Inherits:
Object
  • Object
show all
Extended by:
Gem::Deprecate
Defined in:
lib/tomograph/tomogram.rb,
lib/tomograph/tomogram/action.rb

Defined Under Namespace

Classes: Action

Instance Method Summary collapse

Constructor Details

#initialize(prefix: '', apib_path: nil, drafter_yaml_path: nil, tomogram_json_path: nil) ⇒ Tomogram

Returns a new instance of Tomogram.



10
11
12
13
14
15
16
17
# File 'lib/tomograph/tomogram.rb', line 10

def initialize(prefix: '', apib_path: nil, drafter_yaml_path: nil, tomogram_json_path: nil)
  @documentation = if tomogram_json_path
                     Tomograph::ApiBlueprint::JsonSchema.new(prefix, tomogram_json_path)
                   else
                     Tomograph::ApiBlueprint::Yaml.new(prefix, apib_path, drafter_yaml_path)
                   end
  @prefix = prefix
end

Instance Method Details

#find_request(method:, path:) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/tomograph/tomogram.rb', line 32

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



40
41
42
43
44
45
46
# File 'lib/tomograph/tomogram.rb', line 40

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

Returns:

  • (Boolean)


52
53
54
# File 'lib/tomograph/tomogram.rb', line 52

def prefix_match?(raw_path)
  raw_path.include?(@prefix)
end

#to_aObject



19
20
21
# File 'lib/tomograph/tomogram.rb', line 19

def to_a
  @actions ||= @documentation.to_tomogram
end

#to_hashObject



23
24
25
# File 'lib/tomograph/tomogram.rb', line 23

def to_hash
  to_a.map(&:to_hash)
end

#to_jsonObject



28
29
30
# File 'lib/tomograph/tomogram.rb', line 28

def to_json
  MultiJson.dump(to_a.map(&:to_hash), pretty: true)
end

#to_resourcesObject



48
49
50
# File 'lib/tomograph/tomogram.rb', line 48

def to_resources
  @resources ||= @documentation.to_resources
end