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, delay: nil, primary: nil) ⇒ HttpTemplate

Returns a new instance of HttpTemplate.



794
795
796
797
798
799
# File 'lib/mockserver/models.rb', line 794

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

Instance Attribute Details

#delayObject

Returns the value of attribute delay.



792
793
794
# File 'lib/mockserver/models.rb', line 792

def delay
  @delay
end

#primaryObject

Returns the value of attribute primary.



792
793
794
# File 'lib/mockserver/models.rb', line 792

def primary
  @primary
end

#templateObject

Returns the value of attribute template.



792
793
794
# File 'lib/mockserver/models.rb', line 792

def template
  @template
end

#template_typeObject

Returns the value of attribute template_type.



792
793
794
# File 'lib/mockserver/models.rb', line 792

def template_type
  @template_type
end

Class Method Details

.from_hash(data) ⇒ Object



810
811
812
813
814
815
816
817
818
819
# File 'lib/mockserver/models.rb', line 810

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

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

.template(template_type, template = nil) ⇒ Object



821
822
823
# File 'lib/mockserver/models.rb', line 821

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

Instance Method Details

#to_hObject



801
802
803
804
805
806
807
808
# File 'lib/mockserver/models.rb', line 801

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