Sha256: 34dd7db6d79ec1b8604f5b4c4e16fd203da4c66f5c30f78e4ad97321416ea142

Contents?: true

Size: 973 Bytes

Versions: 10

Compression:

Stored size: 973 Bytes

Contents

require 'flipper/adapters/sync/synchronizer'
require 'flipper/poller'

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

      # Deprecated
      Poller = ::Flipper::Poller

      # 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

10 entries across 10 versions & 1 rubygems

Version Path
flipper-1.0.0 lib/flipper/adapters/poll.rb
flipper-1.0.0.pre lib/flipper/adapters/poll.rb
flipper-0.28.3 lib/flipper/adapters/poll.rb
flipper-0.28.2 lib/flipper/adapters/poll.rb
flipper-0.28.1 lib/flipper/adapters/poll.rb
flipper-0.28.0 lib/flipper/adapters/poll.rb
flipper-0.27.1 lib/flipper/adapters/poll.rb
flipper-0.27.0 lib/flipper/adapters/poll.rb
flipper-0.26.2 lib/flipper/adapters/poll.rb
flipper-0.26.1 lib/flipper/adapters/poll.rb