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.



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

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.



812
813
814
# File 'lib/mockserver/models.rb', line 812

def delay
  @delay
end

#primaryObject

Returns the value of attribute primary.



812
813
814
# File 'lib/mockserver/models.rb', line 812

def primary
  @primary
end

#templateObject

Returns the value of attribute template.



812
813
814
# File 'lib/mockserver/models.rb', line 812

def template
  @template
end

#template_typeObject

Returns the value of attribute template_type.



812
813
814
# File 'lib/mockserver/models.rb', line 812

def template_type
  @template_type
end

Class Method Details

.from_hash(data) ⇒ Object



830
831
832
833
834
835
836
837
838
839
# File 'lib/mockserver/models.rb', line 830

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



841
842
843
# File 'lib/mockserver/models.rb', line 841

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

Instance Method Details

#to_hObject



821
822
823
824
825
826
827
828
# File 'lib/mockserver/models.rb', line 821

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