Class: ResponseMate::Manifest

Inherits:
Object
  • Object
show all
Defined in:
lib/response_mate/manifest.rb

Overview

Responsible for parsing the requests manifest file to actually operate on the requests

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, environment = nil) ⇒ Manifest


7
8
9
10
11
# File 'lib/response_mate/manifest.rb', line 7

def initialize(filename, environment = nil)
  @filename = filename || ResponseMate.configuration.requests_manifest
  @environment = environment
  parse
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description


5
6
7
# File 'lib/response_mate/manifest.rb', line 5

def description
  @description
end

#environmentObject

Returns the value of attribute environment


4
5
6
# File 'lib/response_mate/manifest.rb', line 4

def environment
  @environment
end

#filenameObject

Returns the value of attribute filename


4
5
6
# File 'lib/response_mate/manifest.rb', line 4

def filename
  @filename
end

#nameObject (readonly)

Returns the value of attribute name


5
6
7
# File 'lib/response_mate/manifest.rb', line 5

def name
  @name
end

#requestsObject

Returns the value of attribute requests


4
5
6
# File 'lib/response_mate/manifest.rb', line 4

def requests
  @requests
end

#requests_textObject

Returns the value of attribute requests_text


4
5
6
# File 'lib/response_mate/manifest.rb', line 4

def requests_text
  @requests_text
end

Instance Method Details

#parseArray

Parse the requests manifest


15
16
17
18
19
20
21
22
23
# File 'lib/response_mate/manifest.rb', line 15

def parse
  preprocess_manifest
  @request_hashes = YAML.load(requests_text).deep_symbolize_keys
  @name = @request_hashes[:name] || filename
  @description = @request_hashes[:description] || ''
  @requests = @request_hashes[:requests].
    map(&:deep_symbolize_keys!).
    map { |rh| ResponseMate::Request.new(rh).normalize! }
end

#requests_for_keys(keys) ⇒ Array

Filters requests based on the supplied Array of keys


28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/response_mate/manifest.rb', line 28

def requests_for_keys(keys)
  return [] if keys.empty?

  existing_keys = requests.map(&:key)
  missing_keys = keys - existing_keys

  if missing_keys.present?
    fail ResponseMate::KeysNotFound.new(missing_keys.join(','))
  end

  requests.select! do |r|
    keys.include? r.key
  end
end