Sha256: f0d4d907607231eed4e5527a94a6972d3465a6debc80ef564a9a65c0b87a1139

Contents?: true

Size: 1.8 KB

Versions: 12

Compression:

Stored size: 1.8 KB

Contents

class Etcdv3::KV
  class Transaction
    include Etcdv3::KV::Requests

    # Available comparison identifiers.
    COMPARISON_IDENTIFIERS = {
      equal: 0,
      greater: 1,
      less: 2,
      not_equal: 3
    }

    # Available targets to compare with.
    TARGETS = {
      version: 0,
      create_revision: 1,
      mod_revision: 2,
      value: 3
    }

    attr_writer :compare, :success, :failure

    def initialize; end

    def compare
      @compare ||= []
    end

    def success
      @success ||= []
    end

    def failure
      @failure ||=[]
    end

    # Request Operations

    # txn.put('my', 'key', lease_id: 1)
    def put(key, value, lease=nil)
      put_request(key, value, lease)
    end

    # txn.get('key')
    def get(key, opts={})
      get_request(key, opts)
    end

    # txn.del('key')
    def del(key, range_end='')
      del_request(key, range_end)
    end

    ###  Compare Operations

    # txn.version('names', :greater, 0 )
    def version(key, compare_type, value)
      generate_compare(:version, key, compare_type, value)
    end

    # txn.value('names', :equal, 'wowza' )
    def value(key, compare_type, value)
      generate_compare(:value, key, compare_type, value)
    end

    # txn.mod_revision('names', :not_equal, 0)
    def mod_revision(key, compare_type, value)
      generate_compare(:mod_revision, key, compare_type, value)
    end

    # txn.create_revision('names', :less, 10)
    def create_revision(key, compare_type, value)
      generate_compare(:create_revision, key, compare_type, value)
    end

    private

    def generate_compare(target_union, key, compare_type, value)
      Etcdserverpb::Compare.new(
        key: key,
        result: COMPARISON_IDENTIFIERS[compare_type],
        target: TARGETS[target_union],
        target_union => value
      )
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/kv/transaction.rb
etcdv3-0.11.6 lib/etcdv3/kv/transaction.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/kv/transaction.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/kv/transaction.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/kv/transaction.rb
etcdv3-0.11.5 lib/etcdv3/kv/transaction.rb
etcdv3-0.11.4 lib/etcdv3/kv/transaction.rb
etcdv3-0.11.3 lib/etcdv3/kv/transaction.rb
etcdv3-0.10.2 lib/etcdv3/kv/transaction.rb
etcdv3-0.10.1 lib/etcdv3/kv/transaction.rb
etcdv3-0.9.0 lib/etcdv3/kv/transaction.rb
etcdv3-0.8.3 lib/etcdv3/kv/transaction.rb