Skip to content

Commit

Permalink
refactor: dry up reform::form and dry validation code
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Apr 18, 2019
1 parent 0f816b9 commit 3229e17
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 33 deletions.
9 changes: 0 additions & 9 deletions lib/pact_broker.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
require 'reform'
require 'reform/form/dry'

require 'pact_broker/version'
require 'pact_broker/logging'
require 'pact_broker/app'
require 'pact_broker/db/log_quietener'

module PactBroker
Reform::Form.class_eval do
feature Reform::Form::Dry
end
end
15 changes: 15 additions & 0 deletions lib/pact_broker/api/contracts/base_contract.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'reform'
require 'reform/form/dry'

Reform::Form.class_eval do
feature Reform::Form::Dry
end

module PactBroker
module Api
module Contracts
class BaseContract < Reform::Form
end
end
end
end
5 changes: 2 additions & 3 deletions lib/pact_broker/api/contracts/pacticipant_name_contract.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
require 'reform'
require 'reform/form'
require 'pact_broker/api/contracts/base_contract'

module PactBroker
module Api
module Contracts
class PacticipantNameContract < Reform::Form
class PacticipantNameContract < BaseContract
property :name
property :name_in_pact
property :pacticipant
Expand Down
7 changes: 3 additions & 4 deletions lib/pact_broker/api/contracts/put_pact_params_contract.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
require 'reform'
require 'reform/form'
require 'pact_broker/api/contracts/base_contract'

module PactBroker
module Api
module Contracts
class PutPacticipantNameContract < Reform::Form
class PutPacticipantNameContract < BaseContract
property :name
property :name_in_pact
property :pacticipant
Expand All @@ -24,7 +23,7 @@ class PutPacticipantNameContract < Reform::Form
end
end

class PutPactParamsContract < Reform::Form
class PutPactParamsContract < BaseContract
property :consumer_version_number
property :consumer, form: PutPacticipantNameContract
property :provider, form: PutPacticipantNameContract
Expand Down
3 changes: 1 addition & 2 deletions lib/pact_broker/api/contracts/request_validations.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'reform'
require 'reform/contract'
require 'net/http'
require 'uri'

module PactBroker
module Api
Expand Down
5 changes: 2 additions & 3 deletions lib/pact_broker/api/contracts/verification_contract.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
require 'reform'
require 'reform/form'
require 'pact_broker/api/contracts/base_contract'
require 'uri'

module PactBroker
module Api
module Contracts
class VerificationContract < Reform::Form
class VerificationContract < BaseContract

property :success
property :provider_version, as: :providerApplicationVersion
Expand Down
5 changes: 2 additions & 3 deletions lib/pact_broker/api/contracts/webhook_contract.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
require 'reform'
require 'reform/form'
require 'pact_broker/api/contracts/base_contract'
require 'pact_broker/webhooks/check_host_whitelist'
require 'pact_broker/webhooks/render'
require 'pact_broker/pacticipants/service'

module PactBroker
module Api
module Contracts
class WebhookContract < Reform::Form
class WebhookContract < BaseContract

def validate(*)
result = super
Expand Down
7 changes: 0 additions & 7 deletions lib/pact_broker/api/resources.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
require 'reform'
require 'reform/form/dry'

Reform::Form.class_eval do
feature Reform::Form::Dry
end

require 'pact_broker/api/resources/base_resource'

Dir.glob(File.expand_path(File.join(__FILE__, "..", "resources", "*.rb"))).sort.each do | path |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'spec_helper'
require 'pact_broker/api/contracts/put_pact_params_contract'

module PactBroker
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'spec_helper'
require 'pact_broker/api/contracts/webhook_contract'
require 'pact_broker/api/decorators/webhook_decorator'

Expand Down

0 comments on commit 3229e17

Please sign in to comment.