Class: Fastly::Version

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

Overview

An iteration of your configuration

Instance Attribute Summary collapse

Attributes inherited from Base

#fetcher

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

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

Constructor Details

This class inherits a constructor from Fastly::Base

Instance Attribute Details

#activeObject

Returns the value of attribute active.



4
5
6
# File 'lib/fastly/version.rb', line 4

def active
  @active
end

#commentObject

Returns the value of attribute comment.



4
5
6
# File 'lib/fastly/version.rb', line 4

def comment
  @comment
end

#deployedObject

Returns the value of attribute deployed.



4
5
6
# File 'lib/fastly/version.rb', line 4

def deployed
  @deployed
end

#lockedObject

Returns the value of attribute locked.



4
5
6
# File 'lib/fastly/version.rb', line 4

def locked
  @locked
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/fastly/version.rb', line 4

def name
  @name
end

#numberObject

Returns the value of attribute number.



4
5
6
# File 'lib/fastly/version.rb', line 4

def number
  @number
end

#service_idObject

Returns the value of attribute service_id.



4
5
6
# File 'lib/fastly/version.rb', line 4

def service_id
  @service_id
end

#stagingObject

Returns the value of attribute staging.



4
5
6
# File 'lib/fastly/version.rb', line 4

def staging
  @staging
end

#testingObject

Returns the value of attribute testing.



4
5
6
# File 'lib/fastly/version.rb', line 4

def testing
  @testing
end

Class Method Details

.create_new(fetcher, opts) ⇒ Object

Create an entirely new version, not cloned from the previous one.



91
92
93
94
95
96
# File 'lib/fastly/version.rb', line 91

def self.create_new(fetcher, opts)
  hash = fetcher.client.post(Version.post_path(opts))
  return nil if hash.nil?

  Version.new(hash, fetcher)
end

.delete_path(obj) ⇒ Object



168
169
170
# File 'lib/fastly/version.rb', line 168

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

.get_path(service, number) ⇒ Object



156
157
158
# File 'lib/fastly/version.rb', line 156

def self.get_path(service, number)
  "/service/#{service}/version/#{number}"
end

.post_path(opts = {}) ⇒ Object



160
161
162
# File 'lib/fastly/version.rb', line 160

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

.put_path(obj) ⇒ Object



164
165
166
# File 'lib/fastly/version.rb', line 164

def self.put_path(obj)
  get_path(obj.service_id, obj.number)
end

Instance Method Details

#activate!Object

Activate this version



72
73
74
75
# File 'lib/fastly/version.rb', line 72

def activate!
  hash = fetcher.client.put("#{Version.put_path(self)}/activate")
  !hash.nil?
end

#active?Boolean

Is version active?

Returns:

  • (Boolean)


67
68
69
# File 'lib/fastly/version.rb', line 67

def active?
  true == @active
end

#cloneObject

Clone this Version



84
85
86
87
88
# File 'lib/fastly/version.rb', line 84

def clone
  hash = fetcher.client.put("#{Version.put_path(self)}/clone")
  return nil if hash.nil?
  Version.new(hash, fetcher)
end

#deactivate!Object

Deactivate this version



78
79
80
81
# File 'lib/fastly/version.rb', line 78

def deactivate!
  hash = fetcher.client.put("#{Version.put_path(self)}/deactivate")
  !hash.nil?
end

#delete_vcl(name) ⇒ Object

Delete a VCL file for this Version



137
138
139
140
# File 'lib/fastly/version.rb', line 137

def delete_vcl(name)
  hash = fetcher.client.delete("#{Version.put_path(self)}/vcl/#{name}")
  hash.nil? ? nil : hash
end

#dictionariesObject



142
143
144
# File 'lib/fastly/version.rb', line 142

def dictionaries
  fetcher.list_dictionaries(:service_id => service_id, :version => number)
end

#generated_vcl(opts = {}) ⇒ Object

Get the generated VCL object for this Version (which must have been activated first)

Won’t return the content of the VCL unless you pass in

:include_content => true

in the opts



103
104
105
106
107
108
109
110
111
112
113
# File 'lib/fastly/version.rb', line 103

def generated_vcl(opts = {})
  hash = fetcher.client.get("#{Version.put_path(self)}/generated_vcl", opts)
  opts = {
    'content'    => hash['vcl'] || hash['content'],
    'name'       => hash['md5'],
    'version'    => hash['version'],
    'service_id' => hash['service']
  }

  VCL.new(opts, fetcher)
end

#locked?Boolean

Is this Version locked

Returns:

  • (Boolean)


52
53
54
# File 'lib/fastly/version.rb', line 52

def locked?
  true == @locked
end

#serviceObject

Get the Service object this Version belongs to



57
58
59
# File 'lib/fastly/version.rb', line 57

def service
  fetcher.get(Service, service_id)
end

#settingsObject

Get the Settings object for this Version



62
63
64
# File 'lib/fastly/version.rb', line 62

def settings
  fetcher.get_settings(service_id, number)
end

#upload_main_vcl(name, contents) ⇒ Object

Upload a VCL file for this Version and set as the main VCL



123
124
125
# File 'lib/fastly/version.rb', line 123

def upload_main_vcl(name, contents)
  upload_vcl(name, contents).set_main!
end

#upload_vcl(name, content) ⇒ Object

Upload a VCL file for this Version



116
117
118
119
120
# File 'lib/fastly/version.rb', line 116

def upload_vcl(name, content)
  hash = fetcher.client.post("#{Version.put_path(self)}/vcl", name: name, content: content)
  return nil if hash.nil?
  VCL.new(hash, fetcher)
end

#validateObject

Validate this Version



147
148
149
150
151
152
153
154
# File 'lib/fastly/version.rb', line 147

def validate
  hash = fetcher.client.get("#{Version.put_path(self)}/validate")

  valid = ("ok" == hash["status"])
  message = hash['msg']

  [valid, message]
end

#vcl(name, opts = {}) ⇒ Object

Get the named VCL for this version

Won’t return the content of the VCL unless you pass in

:include_content => true

in the opts



132
133
134
# File 'lib/fastly/version.rb', line 132

def vcl(name, opts = {})
  fetcher.get_vcl(service_id, number, name, opts)
end