Class: PactBroker::Api::Resources::Tag

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

Instance Method Summary collapse

Instance Method Details

#allowed_methodsObject



16
17
18
# File 'lib/pact_broker/api/resources/tag.rb', line 16

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

#content_types_acceptedObject



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

def content_types_accepted
  [["application/json", :from_json]]
end

#content_types_providedObject



8
9
10
# File 'lib/pact_broker/api/resources/tag.rb', line 8

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

#delete_resourceObject



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

def delete_resource
  tag_service.delete identifier_from_path
  true
end

#from_jsonObject



20
21
22
23
24
25
26
27
# File 'lib/pact_broker/api/resources/tag.rb', line 20

def from_json
  unless tag
    @tag = tag_service.create identifier_from_path
    # Make it return a 201 by setting the Location header
    response.headers["Location"] = tag_url(base_url, tag)
  end
  response.body = to_json
end

#policy_nameObject



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

def policy_name
  :'tags::tag'
end

#resource_exists?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/pact_broker/api/resources/tag.rb', line 29

def resource_exists?
  !!tag
end

#tagObject



37
38
39
# File 'lib/pact_broker/api/resources/tag.rb', line 37

def tag
  @tag ||= tag_service.find identifier_from_path
end

#to_jsonObject



33
34
35
# File 'lib/pact_broker/api/resources/tag.rb', line 33

def to_json
  PactBroker::Api::Decorators::TagDecorator.new(tag).to_json(decorator_options)
end