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

#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.



96
97
98
99
100
101
# File 'lib/fastly/version.rb', line 96

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



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

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

.get_path(service, number) ⇒ Object



153
154
155
# File 'lib/fastly/version.rb', line 153

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

.post_path(opts = {}) ⇒ Object



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

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

.put_path(obj) ⇒ Object



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

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

Instance Method Details

#activate!Object

Activate this version



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

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

#active?Boolean

Is version active?

Returns:

  • (Boolean)


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

def active?
  @active.to_i > 0
end

#cloneObject

Clone this Version



89
90
91
92
93
# File 'lib/fastly/version.rb', line 89

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



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

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



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

def delete_vcl(name)
  hash = fetcher.client.delete("#{Version.put_path(self)}/vcl/#{name}")
  hash.nil? ? nil : hash
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



108
109
110
111
112
113
114
115
116
117
118
# File 'lib/fastly/version.rb', line 108

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=(is_locked) ⇒ Object

Set whether this Version is locked



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

def locked=(is_locked)
  @locked = is_locked ? '1' : '0'
end

#locked?Boolean

Is this Version locked

Returns:

  • (Boolean)


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

def locked?
  @locked.to_i > 0
end

#serviceObject

Get the Service object this Version belongs to



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

def service
  fetcher.get(Service, service_id)
end

#settingsObject

Get the Settings object for this Version



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

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



128
129
130
# File 'lib/fastly/version.rb', line 128

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



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

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



148
149
150
151
# File 'lib/fastly/version.rb', line 148

def validate
  hash = fetcher.client.get("#{Version.put_path(self)}/validate")
  !hash.nil?
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



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

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