Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zs/2.2.6 #89

Merged
merged 23 commits into from
Jul 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f87c433
Merge pull request #2 from launchdarkly/jkodumal/ch984/bump-celluloid…
jkodumal Mar 8, 2017
be45e38
Merge branch 'master' of github.com:launchdarkly/ruby-client into pub…
adamlaunchingdarkly Mar 27, 2017
cd807e9
rails 5.1 support
adamlaunchingdarkly Mar 27, 2017
f37c620
Merge pull request #4 from launchdarkly/ac/nio4r
adamlaunchingdarkly Mar 27, 2017
c0b7240
Merge branch 'master' into ac/nio4r
adamlaunchingdarkly Mar 28, 2017
6ebf107
Merge pull request #5 from launchdarkly/ac/nio4r
adamlaunchingdarkly Mar 28, 2017
d83a945
Merge branch 'master' of github.com:launchdarkly/ruby-client-private
adamlaunchingdarkly Mar 28, 2017
41d56ef
Add proxy config
dlau Apr 25, 2017
8da918b
Add proxy support to polling
dlau Apr 25, 2017
c987c91
Fix encoding issue deserializing responses
dlau Apr 25, 2017
71f0889
Pass proxy to streaming EventSource
dlau Apr 26, 2017
4514441
Sync to branch
dlau May 2, 2017
f3d4312
Bump celluloid eventsource
dlau May 5, 2017
fd03386
Merge branch 'bump-eventsource' into proxy
dlau May 5, 2017
7e04460
Revert "Fix encoding issue deserializing responses"
dlau May 5, 2017
177c92e
Merge pull request #6 from launchdarkly/proxy
dlau May 8, 2017
f61d5c7
Rubocop cleanup (#7)
zsiddique Jul 12, 2017
6c49856
Zs/readme update (#8)
zsiddique Jul 26, 2017
3c645b1
Merge branch 'master' of github.com:launchdarkly/ruby-client
Jul 26, 2017
a493ce0
bump patch version
Jul 26, 2017
455c8ef
Fixed a bad merge
Jul 26, 2017
77b692a
new release script
Jul 26, 2017
80064ff
Merge pull request #9 from launchdarkly/zs/add_release_script
zsiddique Jul 26, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
*.a
mkmf.log
*.gem
Gemfile.lock
Gemfile.lock
.DS_Store
69 changes: 34 additions & 35 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Rails/Delegate:
Description: 'Prefer delegate method for delegations.'
Enabled: false

Style/DeprecatedHashMethods:
Style/PreferredHashMethods:
Description: 'Checks for use of deprecated Hash methods.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-key'
Enabled: false
Expand All @@ -103,11 +103,6 @@ Style/Documentation:
Description: 'Document classes and non-namespace modules.'
Enabled: false

Style/DotPosition:
Description: 'Checks the position of the dot in multi-line method calls.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains'
EnforcedStyle: trailing

Style/DoubleNegation:
Description: 'Checks for uses of double negation (!!).'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-bang-bang'
Expand All @@ -133,10 +128,6 @@ Style/EvenOdd:
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#predicate-methods'
Enabled: false

Style/ExtraSpacing:
Description: 'Do not use unnecessary spacing.'
Enabled: true

Style/FileName:
Description: 'Use snake_case for source file names.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#snake-case-files'
Expand Down Expand Up @@ -196,9 +187,9 @@ Style/LineEndConcatenation:
Enabled: false

Metrics/LineLength:
Description: 'Limit lines to 100 characters.'
Description: 'Limit lines to 150 characters.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#80-character-limits'
Max: 100
Max: 150

Metrics/MethodLength:
Description: 'Avoid methods longer than 10 lines of code.'
Expand All @@ -210,13 +201,6 @@ Style/ModuleFunction:
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#module-function'
Enabled: false

Style/MultilineOperationIndentation:
Description: >-
Checks indentation of binary operations that span more than
one line.
Enabled: true
EnforcedStyle: indented

Style/NegatedIf:
Description: >-
Favor unless over if for negative conditions
Expand Down Expand Up @@ -334,13 +318,14 @@ Style/StringLiterals:
EnforcedStyle: double_quotes
Enabled: true

Style/TrailingComma:
Description: 'Checks for trailing comma in parameter lists and literals.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
EnforcedStyleForMultiline: comma
SupportedStyles:
- comma
- no_comma
Style/TrailingCommaInArguments:
Description: 'Checks for trailing comma in argument lists.'
StyleGuide: '#no-trailing-params-comma'
Enabled: true

Style/TrailingCommaInLiteral:
Description: 'Checks for trailing comma in array and hash literals.'
StyleGuide: '#no-trailing-array-commas'
Enabled: true

Style/TrivialAccessors:
Expand Down Expand Up @@ -372,6 +357,29 @@ Style/WordArray:
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-w'
Enabled: false

# Layout
Layout/DotPosition:
Description: 'Checks the position of the dot in multi-line method calls.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains'
EnforcedStyle: trailing

Layout/ExtraSpacing:
Description: 'Do not use unnecessary spacing.'
Enabled: true

Layout/MultilineOperationIndentation:
Description: >-
Checks indentation of binary operations that span more than
one line.
Enabled: true
EnforcedStyle: indented

Layout/InitialIndentation:
Description: >-
Checks the indentation of the first non-blank non-comment line in a file.
Enabled: false


# Lint

Lint/AmbiguousOperator:
Expand Down Expand Up @@ -434,11 +442,6 @@ Lint/InvalidCharacterLiteral:
whitespace character.
Enabled: false

Style/InitialIndentation:
Description: >-
Checks the indentation of the first non-blank non-comment line in a file.
Enabled: false

Lint/LiteralInCondition:
Description: 'Checks of literals used in conditions.'
Enabled: false
Expand Down Expand Up @@ -560,10 +563,6 @@ Rails/Date:
such as Date.today, Date.current etc.
Enabled: false

Rails/DefaultScope:
Description: 'Checks if the argument passed to default_scope is a block.'
Enabled: false

Rails/FindBy:
Description: 'Prefer find_by over where.first.'
Enabled: false
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ Quick setup
0. Install the Ruby SDK with `gem`

```shell
gem install ldclient-rb
gem install ldclient-rb --prerelease
```
Note: The `--prerelease` flag is there to satisfy the dependency of celluloid 0.18pre which we have tested extensively and have found stable in our use case. Unfortunately, the upstream provider has not promoted this version to stable yet. See [here](https://github.com/celluloid/celluloid/issues/762) This is not required for use in a Gemfile.

1. Require the LaunchDarkly client:

Expand Down
6 changes: 3 additions & 3 deletions ext/mkrf_conf.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require 'rubygems'
require "rubygems"


# From http://stackoverflow.com/questions/5830835/how-to-add-openssl-dependency-to-gemspec
# the whole reason this file exists: to return an error if openssl
# isn't installed.
require 'openssl'
require "openssl"

f = File.open(File.join(File.dirname(__FILE__), "Rakefile"), "w") # create dummy rakefile to indicate success
f.write("task :default\n")
f.close
f.close
6 changes: 4 additions & 2 deletions ldclient-rb.gemspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# coding: utf-8

lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "ldclient-rb/version"

# rubocop:disable Metrics/BlockLength
Gem::Specification.new do |spec|
spec.name = "ldclient-rb"
spec.version = LaunchDarkly::VERSION
Expand Down Expand Up @@ -33,8 +35,8 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency "hashdiff", "~> 0.2"
spec.add_runtime_dependency "ld-celluloid-eventsource", "~> 0.10.0"
spec.add_runtime_dependency "celluloid", "~> 0.18.0.pre" # transitive dep; specified here for more control
if RUBY_VERSION >= '2.2.2'

if RUBY_VERSION >= "2.2.2"
spec.add_runtime_dependency "nio4r", "< 3" # for maximum ruby version compatibility.
else
spec.add_runtime_dependency "nio4r", "~> 1.1" # for maximum ruby version compatibility.
Expand Down
1 change: 1 addition & 0 deletions lib/ldclient-rb/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Config
# @option opts [Boolean] :stream (true) Whether or not the streaming API should be used to receive flag updates.
#
# @return [type] [description]
# rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
def initialize(opts = {})
@base_uri = (opts[:base_uri] || Config.default_base_uri).chomp("/")
@stream_uri = (opts[:stream_uri] || Config.default_stream_uri).chomp("/")
Expand Down
32 changes: 14 additions & 18 deletions lib/ldclient-rb/evaluation.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
require "date"

module LaunchDarkly

module Evaluation
BUILTINS = [:key, :ip, :country, :email, :firstName, :lastName, :avatar, :name, :anonymous]

OPERATORS = {
in:
in:
lambda do |a, b|
a == b
end,
endsWith:
endsWith:
lambda do |a, b|
(a.is_a? String) && (a.end_with? b)
end,
startsWith:
startsWith:
lambda do |a, b|
(a.is_a? String) && (a.start_with? b)
end,
Expand Down Expand Up @@ -50,7 +49,7 @@ module Evaluation
end
if b.is_a? String
b = DateTime.rfc3339(b).strftime('%Q').to_i
end
end
(a.is_a? Numeric) ? a < b : false
rescue => e
false
Expand All @@ -60,11 +59,11 @@ module Evaluation
lambda do |a, b|
begin
if a.is_a? String
a = DateTime.rfc3339(a).strftime('%Q').to_i
a = DateTime.rfc3339(a).strftime("%Q").to_i
end
if b.is_a? String
b = DateTime.rfc3339(b).strftime('%Q').to_i
end
b = DateTime.rfc3339(b).strftime("%Q").to_i
end
(a.is_a? Numeric) ? a > b : false
rescue => e
false
Expand Down Expand Up @@ -93,23 +92,22 @@ def evaluate(flag, user, store)
if flag[:on]
res = eval_internal(flag, user, store, events)

return {value: res, events: events} if !res.nil?
return { value: res, events: events } if !res.nil?
end

if !flag[:offVariation].nil? && flag[:offVariation] < flag[:variations].length
value = flag[:variations][flag[:offVariation]]
return {value: value, events: events}
return { value: value, events: events }
end

{value: nil, events: events}
{ value: nil, events: events }
end

def eval_internal(flag, user, store, events)
failed_prereq = false
# Evaluate prerequisites, if any
if !flag[:prerequisites].nil?
flag[:prerequisites].each do |prerequisite|

prereq_flag = store.get(prerequisite[:key])

if prereq_flag.nil? || !prereq_flag[:on]
Expand All @@ -119,7 +117,7 @@ def eval_internal(flag, user, store, events)
prereq_res = eval_internal(prereq_flag, user, store, events)
variation = get_variation(prereq_flag, prerequisite[:variation])
events.push(kind: "feature", key: prereq_flag[:key], value: prereq_res, version: prereq_flag[:version], prereqOf: flag[:key])
if prereq_res.nil? || prereq_res!= variation
if prereq_res.nil? || prereq_res != variation
failed_prereq = true
end
rescue => exn
Expand Down Expand Up @@ -149,7 +147,7 @@ def eval_rules(flag, user)
end
end
end
end
end

# Check custom rules
if !flag[:rules].nil?
Expand Down Expand Up @@ -202,7 +200,7 @@ def clause_match_user(clause, user)
end

maybe_negate(clause, match_any(op, val, clause[:values]))
end
end

def variation_for_user(rule, user, flag)
if !rule[:variation].nil? # fixed variation
Expand Down Expand Up @@ -234,7 +232,7 @@ def bucket_user(user, key, bucket_by, salt)
hash_key = "%s.%s.%s" % [key, salt, id_hash]

hash_val = (Digest::SHA1.hexdigest(hash_key))[0..14]
hash_val.to_i(16) / Float(0xFFFFFFFFFFFFFFF)
hash_val.to_i(16) / Float(0xFFFFFFFFFFFFFFF)
end

def user_value(user, attribute)
Expand All @@ -260,6 +258,4 @@ def match_any(op, value, values)
return false
end
end

end

6 changes: 2 additions & 4 deletions lib/ldclient-rb/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
require "faraday"

module LaunchDarkly

class EventProcessor
def initialize(sdk_key, config)
@queue = Queue.new
Expand Down Expand Up @@ -67,9 +66,8 @@ def add_event(event)
else
@config.logger.warn("[LDClient] Exceeded event queue capacity. Increase capacity to avoid dropping events.")
end
end
end

private :create_worker, :post_flushed_events

end
end
end
3 changes: 1 addition & 2 deletions lib/ldclient-rb/feature_store.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require "concurrent/atomics"

module LaunchDarkly

class InMemoryFeatureStore
def initialize
@features = Hash.new
Expand Down Expand Up @@ -57,4 +56,4 @@ def initialized?
@initialized.value
end
end
end
end
Loading