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.



892
893
894
895
896
897
898
# File 'lib/mockserver/models.rb', line 892

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.



890
891
892
# File 'lib/mockserver/models.rb', line 890

def delay
  @delay
end

#primaryObject

Returns the value of attribute primary.



890
891
892
# File 'lib/mockserver/models.rb', line 890

def primary
  @primary
end

#templateObject

Returns the value of attribute template.



890
891
892
# File 'lib/mockserver/models.rb', line 890

def template
  @template
end

#template_fileObject

Returns the value of attribute template_file.



890
891
892
# File 'lib/mockserver/models.rb', line 890

def template_file
  @template_file
end

#template_typeObject

Returns the value of attribute template_type.



890
891
892
# File 'lib/mockserver/models.rb', line 890

def template_type
  @template_type
end

Class Method Details

.from_hash(data) ⇒ Object



910
911
912
913
914
915
916
917
918
919
920
# File 'lib/mockserver/models.rb', line 910

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



922
923
924
# File 'lib/mockserver/models.rb', line 922

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



900
901
902
903
904
905
906
907
908
# File 'lib/mockserver/models.rb', line 900

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



926
927
928
929
# File 'lib/mockserver/models.rb', line 926

def with_template_file(template_file)
  @template_file = template_file
  self
end