Class: Fastly::Base
- Inherits:
-
Object
- Object
- Fastly::Base
- Defined in:
- lib/fastly/base.rb
Overview
Base class for all Fastly objects
Direct Known Subclasses
BelongsToServiceAndVersion, Customer, Invoice, Service, Settings, User, Version
Instance Attribute Summary collapse
-
#fetcher ⇒ Object
:nodoc: all.
Class Method Summary collapse
- .delete_path(obj) ⇒ Object
- .get_path(id) ⇒ Object
- .list_path(opts = {}) ⇒ Object
- .path ⇒ Object
- .post_path(opts = {}) ⇒ Object
- .put_path(obj) ⇒ Object
Instance Method Summary collapse
-
#as_hash ⇒ Object
:nodoc:.
-
#delete! ⇒ Object
Delete this object.
-
#initialize(opts, fetcher) ⇒ Base
constructor
A new instance of Base.
-
#save! ⇒ Object
Save this object.
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
#fetcher ⇒ Object
: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 |
.path ⇒ Object
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_hash ⇒ Object
: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 |