Skip to content

Commit

Permalink
chore: provide setter method for application context
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Dec 2, 2022
1 parent fe63ee1 commit ec43c4b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/pact_broker/api.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "webmachine/adapters/rack_mapped"
require "webmachine/application_monkey_patch"
require "pact_broker/db/models"
require "pact_broker/api/resources"
require "pact_broker/api/decorators"
Expand Down Expand Up @@ -140,10 +141,7 @@ def self.build_api(application_context = PactBroker::ApplicationContext.default_
end
end

# naughty, but better than setting each route manually
pact_api.routes.each do | route |
route.instance_variable_get(:@bindings)[:application_context] = application_context
end
pact_api.application_context = application_context

pact_api.configure do |config|
config.adapter = :RackMapped
Expand Down
10 changes: 10 additions & 0 deletions lib/webmachine/application_monkey_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require "webmachine/application"

class Webmachine::Application
def application_context= application_context
# naughty, but better than setting each route manually
routes.each do | route |
route.instance_variable_get(:@bindings)[:application_context] = application_context
end
end
end

0 comments on commit ec43c4b

Please sign in to comment.