Class: PactBroker::Api::Resources::Matrix

Inherits:
BaseResource
  • Object
show all
Defined in:
lib/pact_broker/api/resources/matrix.rb

Direct Known Subclasses

CanIDeploy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMatrix

Returns a new instance of Matrix.



12
13
14
15
# File 'lib/pact_broker/api/resources/matrix.rb', line 12

def initialize
  super
  @selectors, @options = PactBroker::Matrix::ParseQuery.call(request.uri.query)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/pact_broker/api/resources/matrix.rb', line 10

def options
  @options
end

#selectorsObject (readonly)

Returns the value of attribute selectors.



10
11
12
# File 'lib/pact_broker/api/resources/matrix.rb', line 10

def selectors
  @selectors
end

Instance Method Details

#allowed_methodsObject



24
25
26
# File 'lib/pact_broker/api/resources/matrix.rb', line 24

def allowed_methods
  ["GET", "OPTIONS"]
end

#content_types_providedObject



17
18
19
20
21
22
# File 'lib/pact_broker/api/resources/matrix.rb', line 17

def content_types_provided
  [
    ["application/hal+json", :to_json],
    ["text/plain", :to_text]
  ]
end

#malformed_request?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
# File 'lib/pact_broker/api/resources/matrix.rb', line 28

def malformed_request?
  error_messages = matrix_service.validate_selectors(selectors)
  if error_messages.any?
    set_json_validation_error_messages error_messages
    true
  else
    false
  end
end

#resultsObject



46
47
48
# File 'lib/pact_broker/api/resources/matrix.rb', line 46

def results
  @results ||= matrix_service.find(selectors, options)
end

#to_jsonObject



38
39
40
# File 'lib/pact_broker/api/resources/matrix.rb', line 38

def to_json
  PactBroker::Api::Decorators::MatrixDecorator.new(results).to_json(decorator_options)
end

#to_textObject



42
43
44
# File 'lib/pact_broker/api/resources/matrix.rb', line 42

def to_text
  PactBroker::Api::Decorators::MatrixTextDecorator.new(results).to_text(decorator_options)
end