Class: Fastly::Base

Inherits:
Object
  • 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

Returns a new instance of Base.



7
8
9
10
11
12
13
14
15
# File 'lib/fastly/base.rb', line 7

def initialize(opts, fetcher)
 @keys = []
 opts.each do |key,val|
   next unless self.respond_to? "#{key}="
   self.send("#{key}=", val)
   @keys.push(key)
 end
 self.fetcher = fetcher
end

Instance Attribute Details

#fetcherObject

:nodoc: all



5
6
7
# File 'lib/fastly/base.rb', line 5

def fetcher
  @fetcher
end

Class Method Details

.delete_path(obj) ⇒ Object



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

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

.get_path(id) ⇒ Object



41
42
43
# File 'lib/fastly/base.rb', line 41

def self.get_path(id)
  "/#{path}/#{id}"
end

.list_path(opts = {}) ⇒ Object



49
50
51
# File 'lib/fastly/base.rb', line 49

def self.list_path(opts={})
  post_path(opts)
end

.pathObject



37
38
39
# File 'lib/fastly/base.rb', line 37

def self.path
  self.to_s.downcase.split("::")[-1]
end

.post_path(opts = {}) ⇒ Object



45
46
47
# File 'lib/fastly/base.rb', line 45

def self.post_path(opts={})
  "/#{path}"
end

.put_path(obj) ⇒ Object



53
54
55
# File 'lib/fastly/base.rb', line 53

def self.put_path(obj)
  get_path(obj.id)
end

Instance Method Details

#as_hashObject

:nodoc:



29
30
31
32
33
34
35
# File 'lib/fastly/base.rb', line 29

def as_hash
  ret = {}
  @keys.each do |key|
    ret[key] = self.send("#{key}") unless key =~ /^_/;
  end
  ret
end

#delete!Object

Delete this object



23
24
25
# File 'lib/fastly/base.rb', line 23

def delete!
  fetcher.delete(self.class, self)
end

#save!Object

Save this object



18
19
20
# File 'lib/fastly/base.rb', line 18

def save!
  fetcher.update(self.class, self)
end