Class: Itly::Plugin::SchemaValidator
- Inherits:
-
Itly::Plugin
- Object
- Itly::Plugin
- Itly::Plugin::SchemaValidator
- Defined in:
- lib/itly/plugin/schema_validator/schema_validator.rb,
lib/itly/plugin/schema_validator/version.rb
Overview
Schema Validator plugin class for Itly SDK
Automatically loaded at runtime in any new Itly
object
Constant Summary collapse
- VERSION =
'0.1.1'
Instance Attribute Summary collapse
-
#disabled ⇒ Object
readonly
Returns the value of attribute disabled.
Instance Method Summary collapse
-
#id ⇒ String
Get the plugin ID.
-
#initialize(schemas:, disabled: false) ⇒ SchemaValidator
constructor
Instantiate a new Plugin::SchemaValidator.
-
#load(options:) ⇒ Object
Initialize the Plugin::SchemaValidator object.
-
#validate(event:) ⇒ Itly::ValidationResponse
Validate an Event.
Constructor Details
#initialize(schemas:, disabled: false) ⇒ SchemaValidator
Instantiate a new Plugin::SchemaValidator
27 28 29 30 31 32 |
# File 'lib/itly/plugin/schema_validator/schema_validator.rb', line 27 def initialize(schemas:, disabled: false) super() @schemas = schemas @disabled = disabled @validators = {} end |
Instance Attribute Details
#disabled ⇒ Object (readonly)
Returns the value of attribute disabled.
14 15 16 |
# File 'lib/itly/plugin/schema_validator/schema_validator.rb', line 14 def disabled @disabled end |
Instance Method Details
#id ⇒ String
Get the plugin ID
88 89 90 |
# File 'lib/itly/plugin/schema_validator/schema_validator.rb', line 88 def id 'schema_validator' end |
#load(options:) ⇒ Object
Initialize the Plugin::SchemaValidator object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/itly/plugin/schema_validator/schema_validator.rb', line 39 def load(options:) super # Get options @logger = .logger # Log @logger&.info "#{id}: load()" @logger&.info "#{id}: plugin is disabled!" if @disabled end |
#validate(event:) ⇒ Itly::ValidationResponse
Validate an Event
Call event
on all plugins and collect their return values.
by the plugins or nil to indicate that there were no error
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/itly/plugin/schema_validator/schema_validator.rb', line 60 def validate(event:) super return unless enabled? # Log log = Itly::Loggers.vars_to_log event: event @logger&.info "#{id}: validate(#{log})" # Check that we have a schema for this event if @schemas[event.name.to_sym].nil? raise Itly::ValidationError, "Event '#{event.name}' not found in tracking plan." end # Lazily initialize and cache validator @validators[event.name.to_sym] ||= JSONSchemer.schema(@schemas[event.name.to_sym]) # Validation properties = deeply_stringify_keys event.properties result = @validators[event.name.to_sym].validate properties return_validation_responses event, result end |