Skip to content

Commit

Permalink
Merge pull request #67 from launchdarkly/jko/v2-evaluation
Browse files Browse the repository at this point in the history
Update to v2
  • Loading branch information
jkodumal authored Jul 21, 2016
2 parents 4ab3d68 + acd226a commit e0b8a4d
Show file tree
Hide file tree
Showing 16 changed files with 676 additions and 782 deletions.
3 changes: 2 additions & 1 deletion ldclient-rb.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency "net-http-persistent", "~> 2.9"
spec.add_runtime_dependency "concurrent-ruby", "~> 1.0.0"
spec.add_runtime_dependency "hashdiff", "~> 0.2"
spec.add_runtime_dependency "ld-celluloid-eventsource", "~> 0.4"
spec.add_runtime_dependency "ld-celluloid-eventsource", "~> 0.4"
spec.add_runtime_dependency "waitutil", "0.2"
end
8 changes: 6 additions & 2 deletions lib/ldclient-rb.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
require "ldclient-rb/version"
require "ldclient-rb/settings"
require "ldclient-rb/evaluation"
require "ldclient-rb/ldclient"
require "ldclient-rb/store"
require "ldclient-rb/cache_store"
require "ldclient-rb/config"
require "ldclient-rb/newrelic"
require "ldclient-rb/stream"
require "ldclient-rb/polling"
require "ldclient-rb/events"
require "ldclient-rb/feature_store"
require "ldclient-rb/requestor"
File renamed without changes.
55 changes: 26 additions & 29 deletions lib/ldclient-rb/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ class Config
# connections in seconds.
# @option opts [Float] :connect_timeout (2) The connect timeout for network
# connections in seconds.
# @option opts [Object] :store A cache store for the Faraday HTTP caching
# @option opts [Object] :cache_store A cache store for the Faraday HTTP caching
# library. Defaults to the Rails cache in a Rails environment, or a
# thread-safe in-memory store otherwise.
# @option opts [Boolean] :offline (false) Whether the client should be initialized in
# offline mode. In offline mode, default values are returned for all flags and no
# remote network requests are made.
# @option opts [Float] :poll_interval (30) The number of seconds between polls for flag updates
# if streaming is off.
#
# @return [type] [description]
def initialize(opts = {})
Expand All @@ -42,14 +47,14 @@ def initialize(opts = {})
@events_uri = (opts[:events_uri] || Config.default_events_uri).chomp("/")
@capacity = opts[:capacity] || Config.default_capacity
@logger = opts[:logger] || Config.default_logger
@store = opts[:store] || Config.default_store
@cache_store = opts[:cache_store] || Config.default_cache_store
@flush_interval = opts[:flush_interval] || Config.default_flush_interval
@connect_timeout = opts[:connect_timeout] || Config.default_connect_timeout
@read_timeout = opts[:read_timeout] || Config.default_read_timeout
@feature_store = opts[:feature_store] || Config.default_feature_store
@stream = opts.has_key?(:stream) ? opts[:stream] : Config.default_stream
@log_timings = opts.has_key?(:log_timings) ? opts[:log_timings] : Config.default_log_timings
@debug_stream = opts.has_key?(:debug_stream) ? opts[:debug_stream] : Config.default_debug_stream
@offline = opts.has_key?(:offline) ? opts[:offline] : Config.default_offline
@poll_interval = opts.has_key?(:poll_interval) && opts[:poll_interval] > 1 ? opts[:poll_interval] : Config.default_poll_interval
end

#
Expand Down Expand Up @@ -79,13 +84,9 @@ def stream?
@stream
end

#
# Whether we should debug streaming mode. If set, the client will fetch features via polling
# and compare the retrieved feature with the value in the feature store
#
# @return [Boolean] True if we should debug streaming mode
def debug_stream?
@debug_stream
# TODO docs
def offline?
@offline
end

#
Expand All @@ -95,6 +96,11 @@ def debug_stream?
# @return [Float] The configured number of seconds between flushes of the event buffer.
attr_reader :flush_interval

#
# The number of seconds to wait before polling for feature flag updates. This option has no
# effect unless streaming is disabled
attr_reader :poll_interval

#
# The configured logger for the LaunchDarkly client. The client library uses the log to
# print warning and error messages.
Expand All @@ -117,7 +123,7 @@ def debug_stream?
# 'read' and 'write' requests.
#
# @return [Object] The configured store for the Faraday HTTP caching library.
attr_reader :store
attr_reader :cache_store

#
# The read timeout for network connections in seconds.
Expand All @@ -132,16 +138,7 @@ def debug_stream?
attr_reader :connect_timeout

#
# Whether timing information should be logged. If it is logged, it will be logged to the DEBUG
# level on the configured logger. This can be very verbose.
#
# @return [Boolean] True if timing information should be logged.
def log_timings?
@log_timings
end

#
# TODO docs
# A store for feature flag configuration rules.
#
attr_reader :feature_store

Expand Down Expand Up @@ -170,7 +167,7 @@ def self.default_events_uri
"https://events.launchdarkly.com"
end

def self.default_store
def self.default_cache_store
defined?(Rails) && Rails.respond_to?(:cache) ? Rails.cache : ThreadSafeMemoryStore.new
end

Expand All @@ -190,20 +187,20 @@ def self.default_logger
defined?(Rails) && Rails.respond_to?(:logger) ? Rails.logger : ::Logger.new($stdout)
end

def self.default_log_timings
false
end

def self.default_stream
true
end

def self.default_feature_store
nil
InMemoryFeatureStore.new
end

def self.default_debug_stream
def self.default_offline
false
end

def self.default_poll_interval
1
end
end
end
Loading

0 comments on commit e0b8a4d

Please sign in to comment.