Class: ConfigCat::Hooks
- Inherits:
-
Object
- Object
- ConfigCat::Hooks
- Defined in:
- lib/configcat/configcatoptions.rb
Instance Method Summary collapse
- #add_on_client_ready(callback) ⇒ Object
- #add_on_config_changed(callback) ⇒ Object
- #add_on_error(callback) ⇒ Object
- #add_on_flag_evaluated(callback) ⇒ Object
- #clear ⇒ Object
-
#initialize(on_client_ready: nil, on_config_changed: nil, on_flag_evaluated: nil, on_error: nil) ⇒ Hooks
constructor
Events fired by [ConfigCatClient].
- #invoke_on_client_ready ⇒ Object
- #invoke_on_config_changed(config) ⇒ Object
- #invoke_on_error(error) ⇒ Object
- #invoke_on_flag_evaluated(evaluation_details) ⇒ Object
Constructor Details
#initialize(on_client_ready: nil, on_config_changed: nil, on_flag_evaluated: nil, on_error: nil) ⇒ Hooks
Events fired by [ConfigCatClient].
10 11 12 13 14 15 |
# File 'lib/configcat/configcatoptions.rb', line 10 def initialize(on_client_ready: nil, on_config_changed: nil, on_flag_evaluated: nil, on_error: nil) @_on_client_ready_callbacks = on_client_ready ? [on_client_ready] : [] @_on_config_changed_callbacks = on_config_changed ? [on_config_changed] : [] @_on_flag_evaluated_callbacks = on_flag_evaluated ? [on_flag_evaluated] : [] @_on_error_callbacks = on_error ? [on_error] : [] end |
Instance Method Details
#add_on_client_ready(callback) ⇒ Object
17 18 19 |
# File 'lib/configcat/configcatoptions.rb', line 17 def add_on_client_ready(callback) @_on_client_ready_callbacks.push(callback) end |
#add_on_config_changed(callback) ⇒ Object
21 22 23 |
# File 'lib/configcat/configcatoptions.rb', line 21 def add_on_config_changed(callback) @_on_config_changed_callbacks.push(callback) end |
#add_on_error(callback) ⇒ Object
29 30 31 |
# File 'lib/configcat/configcatoptions.rb', line 29 def add_on_error(callback) @_on_error_callbacks.push(callback) end |
#add_on_flag_evaluated(callback) ⇒ Object
25 26 27 |
# File 'lib/configcat/configcatoptions.rb', line 25 def add_on_flag_evaluated(callback) @_on_flag_evaluated_callbacks.push(callback) end |
#clear ⇒ Object
79 80 81 82 83 84 |
# File 'lib/configcat/configcatoptions.rb', line 79 def clear @_on_client_ready_callbacks.clear @_on_config_changed_callbacks.clear @_on_flag_evaluated_callbacks.clear @_on_error_callbacks.clear end |
#invoke_on_client_ready ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/configcat/configcatoptions.rb', line 33 def invoke_on_client_ready @_on_client_ready_callbacks.each { |callback| begin callback.() rescue Exception => e error = "Exception occurred during invoke_on_client_ready callback: #{e}" invoke_on_error(error) ConfigCat.logger.error(error) end } end |
#invoke_on_config_changed(config) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/configcat/configcatoptions.rb', line 45 def invoke_on_config_changed(config) @_on_config_changed_callbacks.each { |callback| begin callback.(config) rescue Exception => e error = "Exception occurred during invoke_on_config_changed callback: #{e}" invoke_on_error(error) ConfigCat.logger.error(error) end } end |
#invoke_on_error(error) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/configcat/configcatoptions.rb', line 69 def invoke_on_error(error) @_on_error_callbacks.each { |callback| begin callback.(error) rescue Exception => e ConfigCat.logger.error("Exception occurred during invoke_on_error callback: #{e}") end } end |
#invoke_on_flag_evaluated(evaluation_details) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/configcat/configcatoptions.rb', line 57 def invoke_on_flag_evaluated(evaluation_details) @_on_flag_evaluated_callbacks.each { |callback| begin callback.(evaluation_details) rescue Exception => e error = "Exception occurred during invoke_on_flag_evaluated callback: #{e}" invoke_on_error(error) ConfigCat.logger.error(error) end } end |