Class: Drnbench::RequestResponse::RequestPattern::Pattern

Inherits:
Object
  • Object
show all
Defined in:
lib/drnbench/request-response/request-pattern.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, group) ⇒ Pattern

Returns a new instance of Pattern.


169
170
171
172
# File 'lib/drnbench/request-response/request-pattern.rb', line 169

def initialize(source, group)
  @source = source
  @group = group
end

Instance Attribute Details

#groupObject (readonly)

Returns the value of attribute group


167
168
169
# File 'lib/drnbench/request-response/request-pattern.rb', line 167

def group
  @group
end

#sourceObject (readonly)

Returns the value of attribute source


167
168
169
# File 'lib/drnbench/request-response/request-pattern.rb', line 167

def source
  @source
end

Class Method Details

.valid_source?(source) ⇒ Boolean

Returns:

  • (Boolean)

159
160
161
162
163
164
# File 'lib/drnbench/request-response/request-pattern.rb', line 159

def valid_source?(source)
  return true if source.is_a?(String)
  return false if source.is_a?(Array)
  return !source.has_key?("patterns") if source.is_a?(Hash)
  false
end

Instance Method Details

#pathObject


174
175
176
177
178
179
180
# File 'lib/drnbench/request-response/request-pattern.rb', line 174

def path
  if @source.is_a?(String)
    @source
  else
    @source["path"]
  end
end

#to_requestObject


182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/drnbench/request-response/request-pattern.rb', line 182

def to_request
  if @source.is_a?(String)
    request = { "path" => @source }
  else
    request = @source
  end
  request["host"] ||= @group.host
  request["port"] ||= @group.port
  request["method"] ||= @group.method
  request["timeout"] ||= @group.timeout
  request
end