Class: Fastly::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/fastly/base.rb
Overview
Base class for all Fastly objects
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(opts, fetcher) ⇒ Base
6
7
8
9
10
11
12
13
14
|
# File 'lib/fastly/base.rb', line 6
def initialize(opts, fetcher)
@keys = []
opts.each do |key, val|
next unless self.respond_to? "#{key}="
send("#{key}=", val)
@keys.push(key)
end
self.fetcher = fetcher
end
|
Instance Attribute Details
#fetcher ⇒ Object
4
5
6
|
# File 'lib/fastly/base.rb', line 4
def fetcher
@fetcher
end
|
Class Method Details
.delete_path(object) ⇒ Object
60
61
62
|
# File 'lib/fastly/base.rb', line 60
def self.delete_path(object)
put_path(object)
end
|
.get_path(id) ⇒ Object
44
45
46
|
# File 'lib/fastly/base.rb', line 44
def self.get_path(id)
"/#{path}/#{id}"
end
|
.list_path(opts = {}) ⇒ Object
52
53
54
|
# File 'lib/fastly/base.rb', line 52
def self.list_path(opts = {})
post_path(opts)
end
|
.path ⇒ Object
40
41
42
|
# File 'lib/fastly/base.rb', line 40
def self.path
Util.class_to_path(self)
end
|
.post_path(_opts = {}) ⇒ Object
48
49
50
|
# File 'lib/fastly/base.rb', line 48
def self.post_path(_opts = {})
"/#{path}"
end
|
.put_path(object) ⇒ Object
56
57
58
|
# File 'lib/fastly/base.rb', line 56
def self.put_path(object)
get_path(object.id)
end
|
Instance Method Details
#as_hash ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/fastly/base.rb', line 28
def as_hash
ret = {}
@keys.each do |key|
ret[key] = send("#{key}") unless key =~ /^_/
end
ret
end
|
#delete! ⇒ Object
22
23
24
|
# File 'lib/fastly/base.rb', line 22
def delete!
fetcher.delete(self.class, self)
end
|
#require_api_key! ⇒ Object
36
37
38
|
# File 'lib/fastly/base.rb', line 36
def require_api_key!
fetcher.client.require_key!
end
|
#save! ⇒ Object
17
18
19
|
# File 'lib/fastly/base.rb', line 17
def save!
fetcher.update(self.class, self)
end
|