Sha256: 5b4b0c5f96ab5b1ba89321ac0bf35591cdc3021c25fec3e20854e2b8895fff1b

Contents?: true

Size: 895 Bytes

Versions: 3

Compression:

Stored size: 895 Bytes

Contents

require 'flipper/adapters/sync/synchronizer'

module Flipper
  module Adapters
    class Poll
      extend Forwardable
      include ::Flipper::Adapter

      # Public: The name of the adapter.
      attr_reader :name, :adapter, :poller

      def_delegators :synced_adapter, :features, :get, :get_multi, :get_all, :add, :remove, :clear, :enable, :disable

      def initialize(poller, adapter)
        @name = :poll
        @adapter = adapter
        @poller = poller
        @last_synced_at = 0
        @poller.start
      end

      private

      def synced_adapter
        @poller.start
        poller_last_synced_at = @poller.last_synced_at.value
        if poller_last_synced_at > @last_synced_at
          Flipper::Adapters::Sync::Synchronizer.new(@adapter, @poller.adapter).call
          @last_synced_at = poller_last_synced_at
        end
        @adapter
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
flipper-0.26.0 lib/flipper/adapters/poll.rb
flipper-0.26.0.rc2 lib/flipper/adapters/poll.rb
flipper-0.26.0.rc1 lib/flipper/adapters/poll.rb