class Itly::Plugin::Testing
Constants
- VERSION
Attributes
Public Class Methods
Instantiate a new Plugin::Testing
@param [TrueClass/FalseClass] disabled: set to true to disable the plugin. Default to false
# File lib/itly/plugin/testing/testing.rb, line 19 def initialize(disabled: false) super() @calls = Concurrent::Hash.new @disabled = disabled end
Public Instance Methods
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
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
Get the plugin ID
@return [String] plugin id
# File lib/itly/plugin/testing/testing.rb, line 102 def id 'testing' end
Initialize TestingApi client
@param [Itly::PluginOptions] options: plugins options
# 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
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
Empty the cache
# File lib/itly/plugin/testing/testing.rb, line 44 def reset @calls.clear end
Private Instance Methods
# File lib/itly/plugin/testing/testing.rb, line 108 def enabled? !@disabled end
# File lib/itly/plugin/testing/testing.rb, line 112 def track_calls(method_name, args) @calls[method_name] ||= [] @calls[method_name] << args end