Sha256: 238de3a3ff53572cbf046b4747161fa92eecd3cab300578aac9bd00d1af54886

Contents?: true

Size: 1.09 KB

Versions: 37

Compression:

Stored size: 1.09 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}="
        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] = send("#{key}") unless key =~ /^_/
      end
      ret
    end

    def require_api_key!
      fetcher.client.require_key!
    end

    def self.path
      Util.class_to_path(self)
    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(object)
      get_path(object.id)
    end

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

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
fastly-3.0.2 lib/fastly/base.rb
fastly-3.0.1 lib/fastly/base.rb
fastly-3.0.0 lib/fastly/base.rb
fastly-2.5.3 lib/fastly/base.rb
fastly-2.5.2 lib/fastly/base.rb
fastly-2.5.1 lib/fastly/base.rb
fastly-2.5.0 lib/fastly/base.rb
fastly-2.4.0 lib/fastly/base.rb
fastly-2.3.1 lib/fastly/base.rb
fastly-2.3.0 lib/fastly/base.rb
fastly-2.2.0 lib/fastly/base.rb
fastly-2.1.0 lib/fastly/base.rb
fastly-2.0.0 lib/fastly/base.rb
fastly-1.15.0 lib/fastly/base.rb
fastly-1.14.0 lib/fastly/base.rb
fastly-1.13.2 lib/fastly/base.rb
fastly-1.13.1 lib/fastly/base.rb
fastly-1.13.0 lib/fastly/base.rb
fastly-1.12.0 lib/fastly/base.rb
fastly-1.11.0 lib/fastly/base.rb