Module: ZombieBattleground::Api::Requests::RequestHelper

Included in:
GetCardRequest, GetCardsRequest, GetDeckRequest, GetDecksRequest, GetMatchRequest, GetMatchesRequest
Defined in:
lib/zombie_battleground/api/requests/request_helper.rb

Overview

Provides generic methods for request validator classes

Constant Summary collapse

BLACKLISTED_INSTANCE_VARIABLES =

Instance variables to skip when computing the model’s query paramaters

%w[errors validation_context].freeze

Instance Method Summary collapse

Instance Method Details

#paramsHash

Computes the model’s query paramaters

Examples:

query_params = model.params
query_params # => Hash

Returns:

  • (Hash)


23
24
25
26
27
28
29
30
# File 'lib/zombie_battleground/api/requests/request_helper.rb', line 23

def params
  instance_variables.map do |var|
    normalized_var = var.to_s.gsub(/^@/, '')
    next if BLACKLISTED_INSTANCE_VARIABLES.include?(normalized_var)

    [normalized_var, instance_variable_get(var)]
  end.compact.to_h
end