Class: Itly::Plugin::Testing
- Inherits:
-
Itly::Plugin
- Object
- Itly::Plugin
- Itly::Plugin::Testing
- Defined in:
- lib/itly/plugin/testing/testing.rb,
lib/itly/plugin/testing/version.rb,
lib/itly/plugin/testing/call_options.rb
Overview
Testing plugin class for Itly SDK
Defined Under Namespace
Classes: CallOptions
Constant Summary collapse
- VERSION =
'0.1.1'
Instance Attribute Summary collapse
-
#disabled ⇒ Object
readonly
Returns the value of attribute disabled.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
-
#all(user_id: nil) ⇒ Array
Get all events that was sent to the
track
method. -
#first_of_type(class_name:, user_id: nil) ⇒ Itly::Event
Get the first event that was sent to the
track
method of the specified class name. -
#id ⇒ String
Get the plugin ID.
-
#initialize(disabled: false) ⇒ Testing
constructor
Instantiate a new Plugin::Testing.
-
#load(options:) ⇒ Object
Initialize TestingApi client.
-
#method_name ⇒ Object
Tracking methods.
-
#name ⇒ Object
Testing specific plugin options class for calls to plugin methods.
-
#of_type(class_name:, user_id: nil) ⇒ Array
Get events that was sent to the
track
method of the specified class name. -
#reset ⇒ Object
Empty the cache.
Constructor Details
#initialize(disabled: false) ⇒ Testing
Instantiate a new Plugin::Testing
19 20 21 22 23 |
# File 'lib/itly/plugin/testing/testing.rb', line 19 def initialize(disabled: false) super() @calls = Concurrent::Hash.new @disabled = disabled end |
Instance Attribute Details
#disabled ⇒ Object (readonly)
Returns the value of attribute disabled.
12 13 14 |
# File 'lib/itly/plugin/testing/testing.rb', line 12 def disabled @disabled end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
12 13 14 |
# File 'lib/itly/plugin/testing/testing.rb', line 12 def logger @logger end |
Instance Method Details
#all(user_id: nil) ⇒ Array
Get all events that was sent to the track
method
55 56 57 58 59 |
# 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) ⇒ Itly::Event
Get the first event that was sent to the track
method of the specified class name
82 83 84 |
# 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 ⇒ String
Get the plugin ID
102 103 104 |
# File 'lib/itly/plugin/testing/testing.rb', line 102 def id 'testing' end |
#load(options:) ⇒ Object
Initialize TestingApi client
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/itly/plugin/testing/testing.rb', line 30 def load(options:) super # Get options @logger = .logger # Log logger&.info "#{id}: load()" logger&.info "#{id}: plugin is disabled!" if @disabled end |
#method_name ⇒ Object
Tracking methods
Accept any params, store them in the @calls instance variable
91 92 93 94 95 |
# File 'lib/itly/plugin/testing/testing.rb', line 91 %i[alias identify group track].each do |method_name| define_method method_name do |args| track_calls method_name.to_s, args end end |
#name ⇒ Object
Testing specific plugin options class for calls to plugin methods
16 17 18 19 20 21 22 23 |
# File 'lib/itly/plugin/testing/call_options.rb', line 16 %w[Identify Group Page Track Alias].each do |name| class_eval( <<-EVAL, __FILE__, __LINE__ + 1 class #{name}Options < CallOptions # class IdentifyOptions < CallOptions end # end EVAL ) end |
#of_type(class_name:, user_id: nil) ⇒ Array
Get events that was sent to the track
method of the specified class name
69 70 71 72 |
# 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 ⇒ Object
Empty the cache
44 45 46 |
# File 'lib/itly/plugin/testing/testing.rb', line 44 def reset @calls.clear end |