diff --git a/.rubocop.yml b/.rubocop.yml deleted file mode 100644 index f9ae7181..00000000 --- a/.rubocop.yml +++ /dev/null @@ -1,49 +0,0 @@ -inherit_from: .rubocop_todo.yml - -AllCops: - TargetRubyVersion: 2.3 - -Layout/SpaceInsideHashLiteralBraces: - EnforcedStyle: no_space - -Metrics/AbcSize: - Enabled: false - -Metrics/BlockLength: - Enabled: false - -Metrics/BlockNesting: - Enabled: false - -Metrics/ClassLength: - Enabled: false - -Metrics/CyclomaticComplexity: - Enabled: false - -Metrics/LineLength: - Enabled: false - -Metrics/MethodLength: - Enabled: false - -Metrics/ModuleLength: - Enabled: false - -Metrics/PerceivedComplexity: - Enabled: false - -Naming/VariableNumber: - Enabled: false - -Style/Documentation: - Enabled: false - -Style/RescueStandardError: - Enabled: false - -Style/SignalException: - Enabled: false - -Lint/RescueException: - Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml deleted file mode 100644 index 53c17b56..00000000 --- a/.rubocop_todo.yml +++ /dev/null @@ -1,47 +0,0 @@ -# This configuration was generated by -# `rubocop --auto-gen-config` -# on 2017-12-06 17:48:00 +0500 using RuboCop version 0.51.0. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -# Offense count: 1 -Lint/HandleExceptions: - Exclude: - - 'Rakefile' - -# Offense count: 1 -Lint/LiteralAsCondition: - Exclude: - - 'lib/optimizely/config/datafile_project_config.rb' - -# Offense count: 1 -# Configuration parameters: CountKeywordArgs. -Metrics/ParameterLists: - Max: 6 - Exclude: - - 'lib/optimizely.rb' - - 'lib/optimizely/config_manager/http_project_config_manager.rb' - - 'lib/optimizely/event/batch_event_processor.rb' - - 'lib/optimizely/event/entity/conversion_event.rb' - - 'lib/optimizely/event/entity/event_context.rb' - - 'lib/optimizely/event/entity/impression_event.rb' - - 'lib/optimizely/event/entity/snapshot_event.rb' - - 'lib/optimizely/optimizely_factory.rb' - -Naming/AccessorMethodName: - Exclude: - - 'lib/optimizely/config_manager/http_project_config_manager.rb' - - 'spec/optimizely_factory_spec.rb' - -# Offense count: 1 -# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist, MethodDefinitionMacros. -# NamePrefix: is_, has_, have_ -# NamePrefixBlacklist: is_, has_, have_ -# NameWhitelist: is_a? -# MethodDefinitionMacros: define_method, define_singleton_method -Naming/PredicateName: - Exclude: - - 'spec/**/*' - - 'lib/optimizely.rb' diff --git a/.travis.yml b/.travis.yml index 9f807a80..79e1360b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,6 @@ before_install: install: - bundle install script: "bundle exec rake spec" -before_script: "rubocop" addons: srcclr: true after_success: "coveralls" diff --git a/.yardopts b/.yardopts index 17ef6fad..5eb0aa8d 100644 --- a/.yardopts +++ b/.yardopts @@ -8,4 +8,3 @@ lib/optimizely.rb lib/optimizely/user_profile_service.rb - CONTRIBUTING.md -.rubocop.yml diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8ca6819d..fbe8be1b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 diff --git a/README.md b/README.md index 82e93d23..d71cb18e 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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) diff --git a/lib/optimizely.rb b/lib/optimizely.rb index 1f1cad71..7823d35c 100644 --- a/lib/optimizely.rb +++ b/lib/optimizely.rb @@ -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], @@ -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}'.") @@ -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) diff --git a/lib/optimizely/config_manager/http_project_config_manager.rb b/lib/optimizely/config_manager/http_project_config_manager.rb index fa37711a..ed0fbde4 100644 --- a/lib/optimizely/config_manager/http_project_config_manager.rb +++ b/lib/optimizely/config_manager/http_project_config_manager.rb @@ -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 @@ -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." diff --git a/lib/optimizely/event/batch_event_processor.rb b/lib/optimizely/event/batch_event_processor.rb index 62f43045..f13143e6 100644 --- a/lib/optimizely/event/batch_event_processor.rb +++ b/lib/optimizely/event/batch_event_processor.rb @@ -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 = [] @@ -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? @@ -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 @@ -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 diff --git a/lib/optimizely/event/entity/conversion_event.rb b/lib/optimizely/event/entity/conversion_event.rb index 8859f932..4a82c5fb 100644 --- a/lib/optimizely/event/entity/conversion_event.rb +++ b/lib/optimizely/event/entity/conversion_event.rb @@ -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 diff --git a/lib/optimizely/event/entity/decision.rb b/lib/optimizely/event/entity/decision.rb index 533a91d0..887eed6e 100644 --- a/lib/optimizely/event/entity/decision.rb +++ b/lib/optimizely/event/entity/decision.rb @@ -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 diff --git a/lib/optimizely/event/entity/event_context.rb b/lib/optimizely/event/entity/event_context.rb index 65f8f18e..1aed6bad 100644 --- a/lib/optimizely/event/entity/event_context.rb +++ b/lib/optimizely/event/entity/event_context.rb @@ -20,20 +20,13 @@ class EventContext attr_reader :account_id, :project_id, :anonymize_ip, :revision, :client_name, :client_version - def initialize( - account_id:, - project_id:, - anonymize_ip:, - revision:, - client_name:, - client_version: - ) - @account_id = account_id - @project_id = project_id - @anonymize_ip = anonymize_ip - @revision = revision - @client_name = client_name - @client_version = client_version + def initialize(opts = {}) + @account_id = opts[:account_id] + @project_id = opts[:project_id] + @anonymize_ip = opts[:anonymize_ip] + @revision = opts[:revision] + @client_name = opts[:client_name] + @client_version = opts[:client_version] end def as_json diff --git a/lib/optimizely/event/entity/impression_event.rb b/lib/optimizely/event/entity/impression_event.rb index e0dd3ad9..229e88a4 100644 --- a/lib/optimizely/event/entity/impression_event.rb +++ b/lib/optimizely/event/entity/impression_event.rb @@ -22,24 +22,16 @@ class ImpressionEvent < UserEvent attr_reader :user_id, :experiment_layer_id, :experiment_id, :variation_id, :visitor_attributes, :bot_filtering - def initialize( - event_context:, - user_id:, - experiment_layer_id:, - experiment_id:, - variation_id:, - visitor_attributes:, - bot_filtering: - ) - @event_context = event_context + def initialize(opts = {}) + @event_context = opts[:event_context] @uuid = SecureRandom.uuid @timestamp = Helpers::DateTimeUtils.create_timestamp - @user_id = user_id - @experiment_layer_id = experiment_layer_id - @experiment_id = experiment_id - @variation_id = variation_id - @visitor_attributes = visitor_attributes - @bot_filtering = bot_filtering + @user_id = opts[:user_id] + @experiment_layer_id = opts[:experiment_layer_id] + @experiment_id = opts[:experiment_id] + @variation_id = opts[:variation_id] + @visitor_attributes = opts[:visitor_attributes] + @bot_filtering = opts[:bot_filtering] end end end diff --git a/lib/optimizely/event/entity/snapshot.rb b/lib/optimizely/event/entity/snapshot.rb index 8cab6bb4..012f1048 100644 --- a/lib/optimizely/event/entity/snapshot.rb +++ b/lib/optimizely/event/entity/snapshot.rb @@ -19,9 +19,9 @@ module Optimizely class Snapshot attr_reader :events, :decisions - def initialize(events:, decisions: nil) - @decisions = decisions - @events = events + def initialize(opts = {}) + @decisions = opts[:decisions] + @events = opts[:events] end def as_json diff --git a/lib/optimizely/event/entity/snapshot_event.rb b/lib/optimizely/event/entity/snapshot_event.rb index 5633edad..07590ff2 100644 --- a/lib/optimizely/event/entity/snapshot_event.rb +++ b/lib/optimizely/event/entity/snapshot_event.rb @@ -19,22 +19,14 @@ module Optimizely class SnapshotEvent attr_reader :entity_id, :uuid, :key, :timestamp, :revenue, :value, :tags - def initialize( - entity_id:, - uuid:, - key:, - timestamp:, - revenue: nil, - value: nil, - tags: nil - ) - @entity_id = entity_id - @uuid = uuid - @key = key - @timestamp = timestamp - @revenue = revenue - @value = value - @tags = tags + def initialize(opts = {}) + @entity_id = opts[:entity_id] + @uuid = opts[:uuid] + @key = opts[:key] + @timestamp = opts[:timestamp] + @revenue = opts[:revenue] + @value = opts[:value] + @tags = opts[:tags] end def as_json diff --git a/lib/optimizely/event/entity/visitor.rb b/lib/optimizely/event/entity/visitor.rb index ff6cac48..16a154be 100644 --- a/lib/optimizely/event/entity/visitor.rb +++ b/lib/optimizely/event/entity/visitor.rb @@ -18,10 +18,10 @@ module Optimizely class Visitor attr_reader :snapshots, :visitor_id, :attributes - def initialize(snapshots:, visitor_id:, attributes:) - @snapshots = snapshots - @visitor_id = visitor_id - @attributes = attributes + def initialize(opts = {}) + @snapshots = opts[:snapshots] + @visitor_id = opts[:visitor_id] + @attributes = opts[:attributes] end def as_json diff --git a/lib/optimizely/event/entity/visitor_attribute.rb b/lib/optimizely/event/entity/visitor_attribute.rb index 2ac9df8e..6d5c1428 100644 --- a/lib/optimizely/event/entity/visitor_attribute.rb +++ b/lib/optimizely/event/entity/visitor_attribute.rb @@ -18,11 +18,11 @@ module Optimizely class VisitorAttribute attr_reader :entity_id, :key, :type, :value - def initialize(entity_id:, key:, type:, value:) - @entity_id = entity_id - @key = key - @type = type - @value = value + def initialize(opts = {}) + @entity_id = opts[:entity_id] + @key = opts[:key] + @type = opts[:type] + @value = opts[:value] end def as_json diff --git a/lib/optimizely/event/event_factory.rb b/lib/optimizely/event/event_factory.rb index 754117b5..4845b8e3 100644 --- a/lib/optimizely/event/event_factory.rb +++ b/lib/optimizely/event/event_factory.rb @@ -71,20 +71,22 @@ def create_log_event(user_events, logger) def build_attribute_list(user_attributes, project_config) visitor_attributes = [] - user_attributes&.keys&.each do |attribute_key| - # Omit attribute values that are not supported by the log endpoint. - attribute_value = user_attributes[attribute_key] - next unless Helpers::Validator.attribute_valid?(attribute_key, attribute_value) - - attribute_id = project_config.get_attribute_id attribute_key - next if attribute_id.nil? - - visitor_attributes.push( - entity_id: attribute_id, - key: attribute_key, - type: CUSTOM_ATTRIBUTE_FEATURE_TYPE, - value: attribute_value - ) + if user_attributes && user_attributes.keys + user_attributes.keys.each do |attribute_key| + # Omit attribute values that are not supported by the log endpoint. + attribute_value = user_attributes[attribute_key] + next unless Helpers::Validator.attribute_valid?(attribute_key, attribute_value) + + attribute_id = project_config.get_attribute_id attribute_key + next if attribute_id.nil? + + visitor_attributes.push( + entity_id: attribute_id, + key: attribute_key, + type: CUSTOM_ATTRIBUTE_FEATURE_TYPE, + value: attribute_value + ) + end end return visitor_attributes unless Helpers::Validator.boolean? project_config.bot_filtering diff --git a/lib/optimizely/event/forwarding_event_processor.rb b/lib/optimizely/event/forwarding_event_processor.rb index 8970f301..ee5a3cb3 100644 --- a/lib/optimizely/event/forwarding_event_processor.rb +++ b/lib/optimizely/event/forwarding_event_processor.rb @@ -31,10 +31,10 @@ def process(user_event) 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 diff --git a/lib/optimizely/event_builder.rb b/lib/optimizely/event_builder.rb index b9746bfc..c16f2fde 100644 --- a/lib/optimizely/event_builder.rb +++ b/lib/optimizely/event_builder.rb @@ -65,18 +65,20 @@ def get_common_params(project_config, user_id, attributes) visitor_attributes = [] - attributes&.keys&.each do |attribute_key| - # Omit attribute values that are not supported by the log endpoint. - attribute_value = attributes[attribute_key] - if Helpers::Validator.attribute_valid?(attribute_key, attribute_value) - attribute_id = project_config.get_attribute_id attribute_key - if attribute_id - visitor_attributes.push( - entity_id: attribute_id, - key: attribute_key, - type: CUSTOM_ATTRIBUTE_FEATURE_TYPE, - value: attribute_value - ) + if attributes && attributes.keys + attributes.keys.each do |attribute_key| + # Omit attribute values that are not supported by the log endpoint. + attribute_value = attributes[attribute_key] + if Helpers::Validator.attribute_valid?(attribute_key, attribute_value) + attribute_id = project_config.get_attribute_id attribute_key + if attribute_id + visitor_attributes.push( + entity_id: attribute_id, + key: attribute_key, + type: CUSTOM_ATTRIBUTE_FEATURE_TYPE, + value: attribute_value + ) + end end end end diff --git a/optimizely-sdk.gemspec b/optimizely-sdk.gemspec index fbbddaac..cf817c03 100644 --- a/optimizely-sdk.gemspec +++ b/optimizely-sdk.gemspec @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative 'lib/optimizely/version' +require File.expand_path("../lib/optimizely/version", __FILE__) Gem::Specification.new do |spec| spec.name = 'optimizely-sdk' @@ -20,7 +20,6 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'coveralls' spec.add_development_dependency 'rake' spec.add_development_dependency 'rspec' - spec.add_development_dependency 'rubocop', '0.73.0' spec.add_development_dependency 'webmock' spec.add_runtime_dependency 'httparty', '~> 0.11' diff --git a/spec/event/event_entities_spec.rb b/spec/event/event_entities_spec.rb index 4ce12062..529914d3 100644 --- a/spec/event/event_entities_spec.rb +++ b/spec/event/event_entities_spec.rb @@ -87,7 +87,7 @@ tags: { 'revenue' => 42, 'non-revenue' => 42, - 'value': 1.5 + 'value' => 1.5 } }] }], @@ -165,7 +165,7 @@ tags: { 'revenue' => 42, 'non-revenue' => 42, - 'value': 1.5 + 'value' => 1.5 } ) diff --git a/spec/notification_center_spec.rb b/spec/notification_center_spec.rb index be3a4b8e..4d6db46f 100644 --- a/spec/notification_center_spec.rb +++ b/spec/notification_center_spec.rb @@ -451,7 +451,7 @@ def deliver_three; end expect(spy_logger).to have_received(:log).once .with( Logger::ERROR, - 'Problem calling notify callback. Error: wrong number of arguments (given 0, expected 1)' + 'Problem calling notify callback. Error: wrong number of arguments (0 for 1)' ) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f9dd1dcb..2685aa7d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -17,7 +17,7 @@ # require 'coveralls' Coveralls.wear! -$LOAD_PATH.unshift File.expand_path('../lib', __dir__) +$LOAD_PATH.unshift File.expand_path('../lib', __FILE__) require 'optimizely' require 'spec_params' require 'webmock/rspec'