class ActiveSpy::Rails::Validation::Event
Class responsible to validate event that are send to event-runner instances.
Public Class Methods
new(event_json)
click to toggle source
# File lib/active_spy/rails/validation.rb, line 13 def initialize(event_json) @event = JSON.load(event_json) end
Public Instance Methods
validate!()
click to toggle source
Validates the event_json
provided in the initializer
(see initialize)
# File lib/active_spy/rails/validation.rb, line 20 def validate! check_actor_key(@event['event']['actor']) check_realm_key(@event['event']['realm']) end
Private Instance Methods
check_actor_key(actor)
click to toggle source
Check if actor is valid.
# File lib/active_spy/rails/validation.rb, line 29 def check_actor_key(actor) fail ActorNotPresent if actor.nil? errors = get_errors_from_hash(actor, :actor) fail InvalidActor, errors unless errors.empty? end
check_realm_key(realm)
click to toggle source
Check if realm is valid.
# File lib/active_spy/rails/validation.rb, line 37 def check_realm_key(realm) fail RealmNotPresent if realm.nil? errors = get_errors_from_hash(realm, :realm) fail InvalidRealm, errors unless errors.empty? end
get_errors_from_hash(data, hash_type)
click to toggle source
Get the error from data
regarding hash_type
checking if the required keys are being provided.
# File lib/active_spy/rails/validation.rb, line 46 def get_errors_from_hash(data, hash_type) keys = hash_type == :actor ? required_actor_keys : required_realm_keys keys.map do |key| "#{key} should not be empty." if data[key].nil? end.compact.join(' ') end
required_actor_keys()
click to toggle source
Required keys for an actor to be valid.
# File lib/active_spy/rails/validation.rb, line 55 def required_actor_keys %w[id class login url avatar_url] end
required_realm_keys()
click to toggle source
Required keys for realm to be valid.
# File lib/active_spy/rails/validation.rb, line 61 def required_realm_keys %w[id class name url] end