Sha256: b67f51d4c3f639fa81acbd718f1075a9de0e628a15bf8b3059a22204b6443315

Contents?: true

Size: 1.08 KB

Versions: 27

Compression:

Stored size: 1.08 KB

Contents

class Fastly
  class Dictionary < BelongsToServiceAndVersion
    attr_accessor :id, :name, :service_id

    def items
      fetcher.list_dictionary_items(:service_id => service_id, :dictionary_id => id)
    end

    # Returns a Fastly::DictionaryItem corresponding to this dictionary and the +key+
    #
    # * +key+ - Key of the dictionary item
    def item(key)
      fetcher.get_dictionary_item(service_id, id, key)
    rescue Fastly::Error => e
      raise unless e.message =~ /Record not found/
    end

    def add_item(key, value)
      fetcher.create_dictionary_item(service_id: service_id, dictionary_id: id, item_key: key, item_value: value)
    end

    def update_item(key, value)
      di = items.select {|item| item.item_key.eql? key }.first
      if di
        di.item_value = value
        fetcher.update_dictionary_item(di)
      else
        add_item(key, value)
      end
    end

    def delete_item(key)
      di = items.select {|item| item.item_key.eql? key }.first
      fetcher.delete_dictionary_item(di) if di
    end

    def self.pluralize
      'dictionaries'
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

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