Sha256: 9995b69275fd0cc03b0736abe4c6202a5c738add086628c56e8eb6e47b464b24

Contents?: true

Size: 1.11 KB

Versions: 9

Compression:

Stored size: 1.11 KB

Contents

class Fastly
  # Base class for all Fastly objects
  class Base # :nodoc: all
    attr_accessor :fetcher
    
    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
     
     # Save this object
     def save!
       fetcher.update(self.class, self)
     end

     # Delete this object
     def delete!
       fetcher.delete(self.class, self)
     end
     
     ##
     # :nodoc:
     def as_hash
       ret = {}
       @keys.each do |key|
         ret[key] = self.send("#{key}") unless key =~ /^_/;
       end
       ret
     end

     def self.path
       self.to_s.downcase.split("::")[-1]
     end
     
     def self.get_path(id)
       "/#{path}/#{id}"
     end
     
     def self.post_path(opts={})
       "/#{path}"
     end
     
     def self.list_path(opts={})
       post_path(opts)
     end
     
     def self.put_path(obj)
       get_path(obj.id)
     end
     
     def self.delete_path(obj)
       put_path(obj)
     end
     
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
fastly-1.01 lib/fastly/base.rb
fastly-1.00 lib/fastly/base.rb
fastly-0.99 lib/fastly/base.rb
fastly-0.98 lib/fastly/base.rb
fastly-0.97 lib/fastly/base.rb
fastly-0.96 lib/fastly/base.rb
fastly-0.95 lib/fastly/base.rb
fastly-0.9 lib/fastly/base.rb
fastly-0.5 lib/fastly/base.rb