class Itly::Plugin::Testing

Testing plugin class for Itly SDK

Testing plugin class for Itly SDK

Constants

VERSION

Attributes

disabled[R]
logger[R]

Public Class Methods

new(disabled: false) click to toggle source

Instantiate a new Plugin::Testing

@param [TrueClass/FalseClass] disabled: set to true to disable the plugin. Default to false

Calls superclass method
# File lib/itly/plugin/testing/testing.rb, line 19
def initialize(disabled: false)
  super()
  @calls = Concurrent::Hash.new
  @disabled = disabled
end

Public Instance Methods

all(user_id: nil) click to toggle source

Get all events that was sent to the track method

@param [String] user_id: (optional) filter the events returned by the method by the user_id.

Leave it +nil+ to get all events

@return [Array] array of EvItly::Event objects that was sent to the track method

# File lib/itly/plugin/testing/testing.rb, line 55
def all(user_id: nil)
  calls = @calls['track'].dup
  calls = calls.select { |call| call[:user_id] == user_id } unless user_id.nil?
  calls.collect { |call| call[:event] }
end
first_of_type(class_name:, user_id: nil) click to toggle source

Get the first event that was sent to the track method of the specified class name

@param [Event] class_name: the method return only an event of the specified class name @param [String] user_id: (optional) filter the events returned by the method by the user_id.

Leave it +nil+ to get all events

@return [Itly::Event] object that was sent to the track method. nil if none was found

# File lib/itly/plugin/testing/testing.rb, line 82
def first_of_type(class_name:, user_id: nil)
  of_type(class_name: class_name, user_id: user_id).first
end
id() click to toggle source

Get the plugin ID

@return [String] plugin id

# File lib/itly/plugin/testing/testing.rb, line 102
def id
  'testing'
end
load(options:) click to toggle source

Initialize TestingApi client

@param [Itly::PluginOptions] options: plugins options

Calls superclass method
# File lib/itly/plugin/testing/testing.rb, line 30
def load(options:)
  super
  # Get options
  @logger = options.logger

  # Log
  logger&.info "#{id}: load()"

  logger&.info "#{id}: plugin is disabled!" if @disabled
end
of_type(class_name:, user_id: nil) click to toggle source

Get events that was sent to the track method of the specified class name

@param [Event] class_name: the method return only events of the specified class name @param [String] user_id: (optional) filter the events returned by the method by the user_id.

Leave it +nil+ to get all events

@return [Array] array of Itly::Event objects that was sent to the track method

# File lib/itly/plugin/testing/testing.rb, line 69
def of_type(class_name:, user_id: nil)
  calls = all user_id: user_id
  calls.select { |call| call.is_a? class_name }
end
reset() click to toggle source

Empty the cache

# File lib/itly/plugin/testing/testing.rb, line 44
def reset
  @calls.clear
end

Private Instance Methods

enabled?() click to toggle source
# File lib/itly/plugin/testing/testing.rb, line 108
def enabled?
  !@disabled
end
track_calls(method_name, args) click to toggle source
# File lib/itly/plugin/testing/testing.rb, line 112
def track_calls(method_name, args)
  @calls[method_name] ||= []
  @calls[method_name] << args
end