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.



834
835
836
837
838
839
840
# File 'lib/mockserver/models.rb', line 834

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.



832
833
834
# File 'lib/mockserver/models.rb', line 832

def delay
  @delay
end

#primaryObject

Returns the value of attribute primary.



832
833
834
# File 'lib/mockserver/models.rb', line 832

def primary
  @primary
end

#templateObject

Returns the value of attribute template.



832
833
834
# File 'lib/mockserver/models.rb', line 832

def template
  @template
end

#template_fileObject

Returns the value of attribute template_file.



832
833
834
# File 'lib/mockserver/models.rb', line 832

def template_file
  @template_file
end

#template_typeObject

Returns the value of attribute template_type.



832
833
834
# File 'lib/mockserver/models.rb', line 832

def template_type
  @template_type
end

Class Method Details

.from_hash(data) ⇒ Object



852
853
854
855
856
857
858
859
860
861
862
# File 'lib/mockserver/models.rb', line 852

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



864
865
866
# File 'lib/mockserver/models.rb', line 864

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



842
843
844
845
846
847
848
849
850
# File 'lib/mockserver/models.rb', line 842

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



868
869
870
871
# File 'lib/mockserver/models.rb', line 868

def with_template_file(template_file)
  @template_file = template_file
  self
end