Sha256: 0ea0e6370fbbb3f48df724d3d2e05e95d645cc1e769a2887a8c8a0d78e481e25

Contents?: true

Size: 956 Bytes

Versions: 8

Compression:

Stored size: 956 Bytes

Contents

class Etcdv3::Namespace
  module Utilities
    
    def prepend_prefix(prefix, key)
      key = key.dup if key.frozen?
      key.prepend(prefix)
    end

    def strip_prefix(prefix, resp)
      [:kvs, :prev_kvs].each do |field|
        if resp.respond_to?(field)
          resp.send(field).each do |kv| 
            kv.key = delete_prefix(prefix, kv.key)
          end
        end
      end
      resp
    end

    def strip_prefix_from_lock(prefix, resp)
      if resp.key
        resp.key = delete_prefix(prefix, resp.key)
      end
      resp 
    end

    def strip_prefix_from_events(prefix, events)
      events.each do |event|
        if event.kv
          event.kv.key = delete_prefix(prefix, event.kv.key)
        end
        if event.prev_kv
          event.prev_kv.key = delete_prefix(prefix, event.prev_kv.key)
        end
        event 
      end
    end

    def delete_prefix(prefix, str)
      str.sub(/\A#{prefix}/, '')
    end

  end
end

Version data entries

8 entries across 8 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/namespace/utilities.rb
etcdv3-0.11.6 lib/etcdv3/namespace/utilities.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/namespace/utilities.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/namespace/utilities.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/namespace/utilities.rb
etcdv3-0.11.5 lib/etcdv3/namespace/utilities.rb
etcdv3-0.11.4 lib/etcdv3/namespace/utilities.rb
etcdv3-0.11.3 lib/etcdv3/namespace/utilities.rb