Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Commit

Permalink
Removing rubocop offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariana committed Nov 12, 2014
1 parent 1c40447 commit 3bfae48
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/pacto/native_contract_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@ def initialize(options = {})
end

def build_from_file(contract_path, host)
contract_definition = File.read(contract_path)
if contract_path.to_s.end_with? '.erb'
contract_definition = ERB.new(contract_definition).result
end
definition = JSON.parse(contract_definition)
definition = parse_json(contract_path)
schema.validate definition
definition['request'].merge!('host' => host)

body_to_schema(definition, 'request', contract_path)
body_to_schema(definition, 'response', contract_path)
method_to_http_method(definition, contract_path)
request = RequestClause.new(definition['request'])

request = RequestClause.new(definition['request'].merge('host' => host))
response = ResponseClause.new(definition['response'])
Contract.new(request: request, response: response, file: contract_path, name: definition['name'], examples: definition['examples'])
end
Expand All @@ -40,6 +37,12 @@ def files_for(contracts_dir)

private

def parse_json(path)
contents = File.read(path)
contents = ERB.new(contents).result if path.extname == '.erb'
JSON.parse(contents)
end

def body_to_schema(definition, section, file)
schema = definition[section].delete 'body'
return nil unless schema
Expand Down

0 comments on commit 3bfae48

Please sign in to comment.