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



12
13
14
# File 'lib/fastly/belongs_to_service_and_version.rb', line 12

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

Class Method Details

.delete_path(obj) ⇒ Object



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

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

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



26
27
28
# File 'lib/fastly/belongs_to_service_and_version.rb', line 26

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

.post_path(opts) ⇒ Object



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

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

.put_path(obj) ⇒ Object



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

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

Instance Method Details

#as_hashObject

:nodoc:



22
23
24
# File 'lib/fastly/belongs_to_service_and_version.rb', line 22

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

#serviceObject

Return the Service object this belongs to



7
8
9
# File 'lib/fastly/belongs_to_service_and_version.rb', line 7

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

#version_numberObject

Get the number of the Version this belongs to



17
18
19
# File 'lib/fastly/belongs_to_service_and_version.rb', line 17

def version_number # rubocop:disable all
  @version
end