Class: Committee::Test::ExceptParameter::BaseHashParameterHandler

Inherits:
Object
  • Object
show all
Includes:
StringDummyLookup
Defined in:
lib/committee/test/except_parameter.rb

Overview

Base handler for parameters stored in hash-like structures. Subclasses implement #get_storage and optionally #dummy_value_for.

Direct Known Subclasses

QueryHandler

Instance Method Summary collapse

Constructor Details

#initialize(request, committee_options) ⇒ BaseHashParameterHandler

Returns a new instance of BaseHashParameterHandler.

Parameters:

  • request (Rack::Request)

    The request object

  • committee_options (Hash)

    Committee options hash



114
115
116
117
118
# File 'lib/committee/test/except_parameter.rb', line 114

def initialize(request, committee_options)
  @request = request
  @committee_options = committee_options
  @original_values = {}
end

Instance Method Details

#apply(param_names) ⇒ void

This method returns an undefined value.

Apply dummy values to parameters

Parameters:

  • param_names (Array<String, Symbol>)

    Parameter names to except



123
124
125
126
127
128
129
130
131
132
# File 'lib/committee/test/except_parameter.rb', line 123

def apply(param_names)
  storage = get_storage
  return unless storage

  param_names.each do |param_name|
    key = param_name.to_s
    @original_values[key] = storage[key]
    storage[key] ||= dummy_value_for(key)
  end
end

#restorevoid

This method returns an undefined value.

Restore original parameter values



136
137
138
139
140
141
142
143
# File 'lib/committee/test/except_parameter.rb', line 136

def restore
  storage = get_storage
  return unless storage

  @original_values.each do |key, value|
    value.nil? ? storage.delete(key) : storage[key] = value
  end
end