class Poisol::StubConfigBuilder

Public Class Methods

new() click to toggle source
# File lib/poisol/stub_config/stub_config_builder.rb, line 4
def initialize
  @stub_config = StubConfig.new
  @stub_config.request = RequestConfig.new
  @stub_config.response = ResponseConfig.new
end

Public Instance Methods

build() click to toggle source
# File lib/poisol/stub_config/stub_config_builder.rb, line 30
def build
  @raw_config_hash = Parse.yaml_file @stub_config.file 
  load_schema
  build_request
  build_response
  return @stub_config
end
is_exploded() click to toggle source
# File lib/poisol/stub_config/stub_config_builder.rb, line 25
def is_exploded
  @stub_config.is_inline = false
  self
end
is_inline() click to toggle source
# File lib/poisol/stub_config/stub_config_builder.rb, line 20
def is_inline
  @stub_config.is_inline = true
  self
end
with_domain(domain) click to toggle source
# File lib/poisol/stub_config/stub_config_builder.rb, line 15
def with_domain domain
  @stub_config.request.domain = domain
  self
end
with_file(file_name) click to toggle source
# File lib/poisol/stub_config/stub_config_builder.rb, line 10
def with_file file_name
  @stub_config.file = file_name
  self
end

Private Instance Methods

build_request() click to toggle source
# File lib/poisol/stub_config/stub_config_builder.rb, line 44
def build_request
  load_url
  @stub_config.request.type = @raw_config_hash["request"]["method"].downcase
  load_query
  load_request_body
end
build_response() click to toggle source
# File lib/poisol/stub_config/stub_config_builder.rb, line 77
def build_response
  @stub_config.is_inline ? load_inline_response_body  : load_exploaded_response_body
  load_resonse_array_type
  load_header
end
load_exploaded_request_body() click to toggle source
# File lib/poisol/stub_config/stub_config_builder.rb, line 116
def load_exploaded_request_body
  request_file = "#{File.dirname @stub_config.file}/request.json"
  return  unless File.exists? request_file
  @stub_config.request.body = Parse.json_file_to_hash(request_file)
end
load_exploaded_response_body() click to toggle source
# File lib/poisol/stub_config/stub_config_builder.rb, line 122
def load_exploaded_response_body
  response_file = "#{File.dirname @stub_config.file}/response.json"
  return  unless File.exists? response_file
  @stub_config.response.body = Parse.json_file_to_hash(response_file)
end
load_header() click to toggle source
# File lib/poisol/stub_config/stub_config_builder.rb, line 83
def load_header
  return if @raw_config_hash["response"].blank?
  header = @raw_config_hash["response"]["header"]
  return if header.blank?
  @stub_config.response.header = header
end
load_inline_request_body() click to toggle source
# File lib/poisol/stub_config/stub_config_builder.rb, line 105
def load_inline_request_body
  raw_body = @raw_config_hash["request"]["body"]
  return if raw_body.blank?
  if raw_body.class.name == "String"
    @stub_config.request.body = Parse.json_to_hash raw_body
  else
    @stub_config.request.is_body_key_value = true
    @stub_config.request.body = raw_body
  end
end
load_inline_response_body() click to toggle source
# File lib/poisol/stub_config/stub_config_builder.rb, line 99
def load_inline_response_body
  raw_body = @raw_config_hash["response"]["body"]
  return if raw_body.blank?
  @stub_config.response.body = Parse.json_to_hash raw_body
end
load_query() click to toggle source
# File lib/poisol/stub_config/stub_config_builder.rb, line 57
def load_query
  @stub_config.request.query = @raw_config_hash["request"]["query"]
  query_explicit = @raw_config_hash["request"]["query_explicit"]
  @stub_config.request.query_explicit = query_explicit.blank? ? false : query_explicit
end
load_request_body() click to toggle source
# File lib/poisol/stub_config/stub_config_builder.rb, line 51
def load_request_body
  load_request_body_filed_implicit_option
  @stub_config.is_inline ? load_inline_request_body : load_exploaded_request_body
end
load_request_body_filed_implicit_option() click to toggle source
# File lib/poisol/stub_config/stub_config_builder.rb, line 71
def load_request_body_filed_implicit_option
  body_explicit = @raw_config_hash["request"]["body_explicit"]
  @stub_config.request.body_explicit = body_explicit.blank? ? false : body_explicit
end
load_resonse_array_type() click to toggle source
# File lib/poisol/stub_config/stub_config_builder.rb, line 90
def load_resonse_array_type
  return if @raw_config_hash["response"].blank?
  array_type = @raw_config_hash["response"]["array_type"]
  return if array_type.blank?
  @stub_config.response.is_column_array = true  if array_type.eql? "column"
  @stub_config.response.is_row_array = true  if array_type.eql? "row"
end
load_schema() click to toggle source
# File lib/poisol/stub_config/stub_config_builder.rb, line 40
def load_schema
    @stub_config.schema = @raw_config_hash["schema"]
end
load_url() click to toggle source
# File lib/poisol/stub_config/stub_config_builder.rb, line 64
def load_url
  url = @raw_config_hash["request"]["url"]
  url.strip!
  url.sub!("/","") if url[0].eql? "/"
  @stub_config.request.url = url
end