Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
49 changes: 0 additions & 49 deletions .rubocop.yml

This file was deleted.

47 changes: 0 additions & 47 deletions .rubocop_todo.yml

This file was deleted.

1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ before_install:
install:
- bundle install
script: "bundle exec rake spec"
before_script: "rubocop"
addons:
srcclr: true
after_success: "coveralls"
Expand Down
1 change: 0 additions & 1 deletion .yardopts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ lib/optimizely.rb
lib/optimizely/user_profile_service.rb
-
CONTRIBUTING.md
.rubocop.yml
16 changes: 5 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,17 @@ We welcome contributions and feedback! All contributors must sign our [Contribut
1. Fork the repository and create your branch from master.
2. Please follow the [commit message guidelines](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-commit-message-guidelines) for each commit message.
3. Make sure to add tests!
4. Run `rubocop` to ensure there are no lint errors.
5. `git push` your changes to GitHub.
6. Open a PR from your fork into the master branch of the original repo.
7. Make sure that all unit tests are passing and that there are no merge conflicts between your branch and `master`.
8. Open a pull request from `YOUR_NAME/branch_name` to `master`.
9. A repository maintainer will review your pull request and, if all goes well, squash and merge it!
4. `git push` your changes to GitHub.
5. Open a PR from your fork into the master branch of the original repo.
6. Make sure that all unit tests are passing and that there are no merge conflicts between your branch and `master`.
7. Open a pull request from `YOUR_NAME/branch_name` to `master`.
8. A repository maintainer will review your pull request and, if all goes well, squash and merge it!

## Pull request acceptance criteria

* **All code must have test coverage.** We use rspec. Changes in functionality should have accompanying unit tests. Bug fixes should have accompanying regression tests.
* Tests are located in `/spec` with one file per class.
* Please don't change the Rakefile or VERSION. We'll take care of bumping the version when we next release.
* Lint your code with our [RuboCop rules](.rubocop.yml) before submitting.

## Style

To enforce style rules, we use RuboCop. See our [rubocop.yml](.rubocop.yml) for more information on our specific style rules.

## License

Expand Down
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Optimizely Ruby SDK
# Optimizely Ruby SDK (backported for ruby 1.9.3)
[![Build Status](https://travis-ci.org/optimizely/ruby-sdk.svg?branch=master)](https://travis-ci.org/optimizely/ruby-sdk)
[![Coverage Status](https://coveralls.io/repos/github/optimizely/ruby-sdk/badge.svg)](https://coveralls.io/github/optimizely/ruby-sdk)
[![Apache 2.0](https://img.shields.io/github/license/nebula-plugins/gradle-extra-configurations-plugin.svg)](http://www.apache.org/licenses/LICENSE-2.0)
Expand Down Expand Up @@ -191,10 +191,6 @@ Copyright © 2006 David Chelimsky, The RSpec Development Team
Copyright © 2005 Steven Baker
License (MIT): [https://github.com/rspec/rspec/blob/master/LICENSE.md](https://github.com/rspec/rspec/blob/master/LICENSE.md)

**RuboCop** [https://github.com/rubocop-hq/rubocop](https://github.com/rubocop-hq/rubocop)
Copyright © 2012-19 Bozhidar Batsov
License (MIT): [https://github.com/rubocop-hq/rubocop/blob/master/LICENSE.txt](https://github.com/rubocop-hq/rubocop/blob/master/LICENSE.txt)

**WebMock** [https://github.com/bblimke/webmock](https://github.com/bblimke/webmock)
Copyright © 2009-2010 Bartosz Blimke
License (MIT): [https://github.com/bblimke/webmock/blob/master/LICENSE](https://github.com/bblimke/webmock/blob/master/LICENSE)
6 changes: 3 additions & 3 deletions lib/optimizely.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def track(event_key, user_id, attributes = nil, event_tags = nil)
@event_processor.process(user_event)
@logger.log(Logger::INFO, "Tracking event '#{event_key}' for user '#{user_id}'.")

if @notification_center.notification_count(NotificationCenter::NOTIFICATION_TYPES[:TRACK]).positive?
if @notification_center.notification_count(NotificationCenter::NOTIFICATION_TYPES[:TRACK]) > 0
log_event = EventFactory.create_log_event(user_event, @logger)
@notification_center.send_notifications(
NotificationCenter::NOTIFICATION_TYPES[:TRACK],
Expand Down Expand Up @@ -623,7 +623,7 @@ def get_feature_variable_for_type(feature_flag_key, variable_key, variable_type,
if feature_enabled == true
variation_variable_usages = config.variation_id_to_variable_usage_map[variation['id']]
variable_id = variable['id']
if variation_variable_usages&.key?(variable_id)
if variation_variable_usages && variation_variable_usages.key?(variable_id)
variable_value = variation_variable_usages[variable_id]['value']
@logger.log(Logger::INFO,
"Got variable value '#{variable_value}' for variable '#{variable_key}' of feature flag '#{feature_flag_key}'.")
Expand Down Expand Up @@ -710,7 +710,7 @@ def send_impression(config, experiment, variation_key, user_id, attributes = nil
variation_id = config.get_variation_id_from_key(experiment_key, variation_key)
user_event = UserEventFactory.create_impression_event(config, experiment, variation_id, user_id, attributes)
@event_processor.process(user_event)
return unless @notification_center.notification_count(NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE]).positive?
return unless @notification_center.notification_count(NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE]) > 0

@logger.log(Logger::INFO, "Activating user '#{user_id}' in experiment '#{experiment_key}'.")
variation = config.get_variation_from_id(experiment_key, variation_id)
Expand Down
52 changes: 27 additions & 25 deletions lib/optimizely/config_manager/http_project_config_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,36 @@ class HTTPProjectConfigManager < ProjectConfigManager
# error_handler - Provides a handle_error method to handle exceptions.
# skip_json_validation - Optional boolean param which allows skipping JSON schema
# validation upon object invocation. By default JSON schema validation will be performed.
def initialize(
sdk_key: nil,
url: nil,
url_template: nil,
polling_interval: nil,
blocking_timeout: nil,
auto_update: true,
start_by_default: true,
datafile: nil,
logger: nil,
error_handler: nil,
skip_json_validation: false,
notification_center: nil
)
@logger = logger || NoOpLogger.new
@error_handler = error_handler || NoOpErrorHandler.new
@datafile_url = get_datafile_url(sdk_key, url, url_template)
def initialize(opts = {})
opts = {
sdk_key: nil,
url: nil,
url_template: nil,
polling_interval: nil,
blocking_timeout: nil,
auto_update: true,
start_by_default: true,
datafile: nil,
logger: nil,
error_handler: nil,
skip_json_validation: false,
notification_center: nil
}.merge(opts)

@logger = opts[:logger] || NoOpLogger.new
@error_handler = opts[:error_handler] || NoOpErrorHandler.new
@datafile_url = get_datafile_url(opts[:sdk_key], opts[:url], opts[:url_template])
@polling_interval = nil
polling_interval(polling_interval)
polling_interval(opts[:polling_interval])
@blocking_timeout = nil
blocking_timeout(blocking_timeout)
blocking_timeout(opts[:blocking_timeout])
@last_modified = nil
@async_scheduler = AsyncScheduler.new(method(:fetch_datafile_config), @polling_interval, auto_update, @logger)
@async_scheduler.start! if start_by_default == true
@async_scheduler = AsyncScheduler.new(method(:fetch_datafile_config), @polling_interval, opts[:auto_update], @logger)
@async_scheduler.start! if opts[:start_by_default] == true
@closed = false
@skip_json_validation = skip_json_validation
@notification_center = notification_center.is_a?(Optimizely::NotificationCenter) ? notification_center : NotificationCenter.new(@logger, @error_handler)
@config = datafile.nil? ? nil : DatafileProjectConfig.create(datafile, @logger, @error_handler, @skip_json_validation)
@skip_json_validation = opts[:skip_json_validation]
@notification_center = opts[:notification_center].is_a?(Optimizely::NotificationCenter) ? opts[:notification_center] : NotificationCenter.new(@logger, @error_handler)
@config = opts[:datafile].nil? ? nil : DatafileProjectConfig.create(opts[:datafile], @logger, @error_handler, @skip_json_validation)
@mutex = Mutex.new
@resource = ConditionVariable.new
end
Expand Down Expand Up @@ -219,7 +221,7 @@ def polling_interval(polling_interval)
return
end

unless polling_interval.positive? && polling_interval <= Helpers::Constants::CONFIG_MANAGER['MAX_SECONDS_LIMIT']
unless polling_interval > 0 && polling_interval <= Helpers::Constants::CONFIG_MANAGER['MAX_SECONDS_LIMIT']
@logger.log(
Logger::DEBUG,
"Polling interval '#{polling_interval}' has invalid range. Defaulting to #{Helpers::Constants::CONFIG_MANAGER['DEFAULT_UPDATE_INTERVAL']} seconds."
Expand Down
42 changes: 22 additions & 20 deletions lib/optimizely/event/batch_event_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,32 @@ class BatchEventProcessor < EventProcessor
FLUSH_SIGNAL = 'FLUSH_SIGNAL'
SHUTDOWN_SIGNAL = 'SHUTDOWN_SIGNAL'

def initialize(
event_queue: SizedQueue.new(DEFAULT_QUEUE_CAPACITY),
event_dispatcher: Optimizely::EventDispatcher.new,
batch_size: DEFAULT_BATCH_SIZE,
flush_interval: DEFAULT_BATCH_INTERVAL,
logger: NoOpLogger.new,
notification_center: nil
)
@event_queue = event_queue
@logger = logger
@event_dispatcher = event_dispatcher
@batch_size = if (batch_size.is_a? Integer) && positive_number?(batch_size)
batch_size
def initialize(opts = {})
opts = {
event_queue: SizedQueue.new(DEFAULT_QUEUE_CAPACITY),
event_dispatcher: Optimizely::EventDispatcher.new,
batch_size: DEFAULT_BATCH_SIZE,
flush_interval: DEFAULT_BATCH_INTERVAL,
logger: NoOpLogger.new,
notification_center: nil
}.merge(opts)

@event_queue = opts[:event_queue]
@logger = opts[:logger]
@event_dispatcher = opts[:event_dispatcher]
@batch_size = if (opts[:batch_size].is_a? Integer) && positive_number?(opts[:batch_size])
opts[:batch_size]
else
@logger.log(Logger::DEBUG, "Setting to default batch_size: #{DEFAULT_BATCH_SIZE}.")
DEFAULT_BATCH_SIZE
end
@flush_interval = if positive_number?(flush_interval)
flush_interval
@flush_interval = if positive_number?(opts[:flush_interval])
opts[:flush_interval]
else
@logger.log(Logger::DEBUG, "Setting to default flush_interval: #{DEFAULT_BATCH_INTERVAL} ms.")
DEFAULT_BATCH_INTERVAL
end
@notification_center = notification_center
@notification_center = opts[:notification_center]
@mutex = Mutex.new
@received = ConditionVariable.new
@current_batch = []
Expand Down Expand Up @@ -130,7 +132,7 @@ def run

@mutex.synchronize do
@received.wait(@mutex, 0.05)
item = @event_queue.pop if @event_queue.length.positive?
item = @event_queue.pop if @event_queue.length > 0
end

if item.nil?
Expand Down Expand Up @@ -169,10 +171,10 @@ def flush_queue!
log_event = Optimizely::EventFactory.create_log_event(@current_batch, @logger)
begin
@event_dispatcher.dispatch_event(log_event)
@notification_center&.send_notifications(
@notification_center.send_notifications(
NotificationCenter::NOTIFICATION_TYPES[:LOG_EVENT],
log_event
)
) if @notification_center
rescue StandardError => e
@logger.log(Logger::ERROR, "Error dispatching event: #{log_event} #{e.message}.")
end
Expand Down Expand Up @@ -219,7 +221,7 @@ def should_split?(user_event)
def positive_number?(value)
# Returns true if the given value is positive finite number.
# false otherwise.
Helpers::Validator.finite_number?(value) && value.positive?
Helpers::Validator.finite_number?(value) && value > 0
end
end
end
21 changes: 7 additions & 14 deletions lib/optimizely/event/entity/conversion_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,15 @@ class ConversionEvent < UserEvent
# Represents conversion event
attr_reader :event, :user_id, :visitor_attributes, :tags, :bot_filtering

def initialize(
event_context:,
event:,
user_id:,
visitor_attributes:,
tags:,
bot_filtering:
)
@event_context = event_context
def initialize(opts = {})
@event_context = opts[:event_context]
@uuid = SecureRandom.uuid
@timestamp = Helpers::DateTimeUtils.create_timestamp
@event = event
@user_id = user_id
@visitor_attributes = visitor_attributes
@tags = tags
@bot_filtering = bot_filtering
@event = opts[:event]
@user_id = opts[:user_id]
@visitor_attributes = opts[:visitor_attributes]
@tags = opts[:tags]
@bot_filtering = opts[:bot_filtering]
end
end
end
8 changes: 4 additions & 4 deletions lib/optimizely/event/entity/decision.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ module Optimizely
class Decision
attr_reader :campaign_id, :experiment_id, :variation_id

def initialize(campaign_id:, experiment_id:, variation_id:)
@campaign_id = campaign_id
@experiment_id = experiment_id
@variation_id = variation_id
def initialize(opts = {})
@campaign_id = opts[:campaign_id]
@experiment_id = opts[:experiment_id]
@variation_id = opts[:variation_id]
end

def as_json
Expand Down
Loading