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

Returns a new instance of 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

#requests_for_keys(keys) ⇒ Array

Filters requests based on the supplied Array of keys

Parameters:

  • keys (Array)

    The keys to lookup for matching requests

Returns:

  • (Array)

    of matching requests



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/response_mate/manifest.rb', line 16

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

  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

  requests
end