Class: MockServer::HttpTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/mockserver/models.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template_type: 'JAVASCRIPT', template: nil, template_file: nil, delay: nil, primary: nil) ⇒ HttpTemplate

Returns a new instance of HttpTemplate.



1114
1115
1116
1117
1118
1119
1120
# File 'lib/mockserver/models.rb', line 1114

def initialize(template_type: 'JAVASCRIPT', template: nil, template_file: nil, delay: nil, primary: nil)
  @template_type = template_type
  @template = template
  @template_file = template_file
  @delay = delay
  @primary = primary
end

Instance Attribute Details

#delayObject

Returns the value of attribute delay.



1112
1113
1114
# File 'lib/mockserver/models.rb', line 1112

def delay
  @delay
end

#primaryObject

Returns the value of attribute primary.



1112
1113
1114
# File 'lib/mockserver/models.rb', line 1112

def primary
  @primary
end

#templateObject

Returns the value of attribute template.



1112
1113
1114
# File 'lib/mockserver/models.rb', line 1112

def template
  @template
end

#template_fileObject

Returns the value of attribute template_file.



1112
1113
1114
# File 'lib/mockserver/models.rb', line 1112

def template_file
  @template_file
end

#template_typeObject

Returns the value of attribute template_type.



1112
1113
1114
# File 'lib/mockserver/models.rb', line 1112

def template_type
  @template_type
end

Class Method Details

.from_hash(data) ⇒ Object



1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
# File 'lib/mockserver/models.rb', line 1132

def self.from_hash(data)
  return nil if data.nil?

  new(
    template_type: data.fetch('templateType', 'JAVASCRIPT'),
    template:      data['template'],
    template_file: data['templateFile'],
    delay:         Delay.from_hash(data['delay']),
    primary:       data['primary']
  )
end

.template(template_type, template = nil, template_file: nil) ⇒ Object



1144
1145
1146
# File 'lib/mockserver/models.rb', line 1144

def self.template(template_type, template = nil, template_file: nil)
  new(template_type: template_type, template: template, template_file: template_file)
end

Instance Method Details

#to_hObject



1122
1123
1124
1125
1126
1127
1128
1129
1130
# File 'lib/mockserver/models.rb', line 1122

def to_h
  MockServer.strip_none({
    'templateType' => @template_type,
    'template'     => @template,
    'templateFile' => @template_file,
    'delay'        => @delay&.to_h,
    'primary'      => @primary
  })
end

#with_template_file(template_file) ⇒ Object



1148
1149
1150
1151
# File 'lib/mockserver/models.rb', line 1148

def with_template_file(template_file)
  @template_file = template_file
  self
end