Class: Fastly::BelongsToServiceAndVersion

Inherits:
Base
  • Object
show all
Defined in:
lib/fastly/belongs_to_service_and_version.rb

Overview

Encapsulates behavior of objects requiring both service and version

Instance Attribute Summary collapse

Attributes inherited from Base

#fetcher

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#delete!, #initialize, list_path, path, #require_api_key!, #save!

Constructor Details

This class inherits a constructor from Fastly::Base

Instance Attribute Details

#versionObject

Get the Version object this belongs to



14
15
16
# File 'lib/fastly/belongs_to_service_and_version.rb', line 14

def version
  @version_obj ||= fetcher.get(Fastly::Version, service_id, version_number)
end

Class Method Details

.delete_path(obj) ⇒ Object



47
48
49
# File 'lib/fastly/belongs_to_service_and_version.rb', line 47

def self.delete_path(obj)
  put_path(obj)
end

.get_path(service, version, name, _opts = {}) ⇒ Object



35
36
37
# File 'lib/fastly/belongs_to_service_and_version.rb', line 35

def self.get_path(service, version, name, _opts = {})
  "/service/#{service}/version/#{version}/#{path}/#{path_escape(name)}"
end

.path_escape(path) ⇒ Object

URI escape (including spaces) the path and return it



29
30
31
32
33
# File 'lib/fastly/belongs_to_service_and_version.rb', line 29

def self.path_escape(path)
  @uri_parser ||= URI::Parser.new
  # the leading space in the escape character set is intentional
  @uri_parser.escape(path, ' !*\'();:@&=+$,/?#[]')
end

.post_path(opts) ⇒ Object



39
40
41
# File 'lib/fastly/belongs_to_service_and_version.rb', line 39

def self.post_path(opts)
  "/service/#{opts[:service_id]}/version/#{opts[:version]}/#{path}"
end

.put_path(obj) ⇒ Object



43
44
45
# File 'lib/fastly/belongs_to_service_and_version.rb', line 43

def self.put_path(obj)
  get_path(obj.service_id, obj.version_number, obj.name)
end

Instance Method Details

#as_hashObject

:nodoc:



24
25
26
# File 'lib/fastly/belongs_to_service_and_version.rb', line 24

def as_hash
  super.delete_if { |var| %w(service_id version).include?(var) }
end

#serviceObject

Return the Service object this belongs to



9
10
11
# File 'lib/fastly/belongs_to_service_and_version.rb', line 9

def service
  @service ||= fetcher.get(Service, service_id)
end

#version_numberObject

Get the number of the Version this belongs to



19
20
21
# File 'lib/fastly/belongs_to_service_and_version.rb', line 19

def version_number # rubocop:disable all
  @version
end