-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathbody.rb
More file actions
60 lines (51 loc) · 1.32 KB
/
body.rb
File metadata and controls
60 lines (51 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# encoding: UTF-8
require 'hashie'
require_relative './parameter'
require_relative './enum'
#
# A model for a a body in a request object.
# @author: Nayyara Samuel (mailto: nayyara.samuel@opower.com)
#
module MockServer::Model
# An enum for body type
class BodyType < SymbolizedEnum
def allowed_values
[:STRING, :REGEX, :XPATH, :PARAMETERS, :BINARY]
end
end
# A model for a a body in a request object.
class Body < Hashie::Dash
include Hashie::Extensions::MethodAccess
include Hashie::Extensions::IgnoreUndeclared
include Hashie::Extensions::Coercion
property :type, required: true
property :body
property :xpath
property :string
property :parameters
coerce_key :type, BodyType
coerce_key :body, String
coerce_key :xpath, String
coerce_key :string, String
coerce_key :parameters, Parameters
end
# DSL methods related to body
module DSL
# For response object where body can only be a string
def body(value)
value
end
def exact(value)
Body.new(type: :STRING, string: value)
end
def regex(value)
Body.new(type: :REGEX, body: value)
end
def xpath(value)
Body.new(type: :XPATH, xpath: value)
end
def parameterized(*parameters)
Body.new(type: :PARAMETERS, parameters: parameters)
end
end
end