Skip to content

Commit

Permalink
Use dry-system for all dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
davydovanton committed Jun 15, 2017
1 parent 06b4cc7 commit 2a62c83
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 10 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Expand Up @@ -21,6 +21,8 @@ gem 'hanami-serializer', github: 'davydovanton/hanami-serializer'
gem 'sidekiq'
gem 'sidekiq-scheduler'

gem 'dry-system'

gem 'redis', '~>3.2'
gem 'hiredis'
gem 'mock_redis'
Expand Down
10 changes: 10 additions & 0 deletions Gemfile.lock
Expand Up @@ -25,6 +25,8 @@ GEM
diff-lcs (1.3)
docile (1.1.5)
dotenv (2.2.0)
dry-auto_inject (0.4.3)
dry-container (>= 0.3.4)
dry-configurable (0.6.2)
concurrent-ruby (~> 1.0)
dry-container (0.6.0)
Expand All @@ -43,6 +45,13 @@ GEM
dry-equalizer (~> 0.2)
dry-types (~> 0.9, >= 0.9.0)
ice_nine (~> 0.11)
dry-system (0.6.0)
concurrent-ruby (~> 1.0)
dry-auto_inject (>= 0.4.0)
dry-configurable (~> 0.2)
dry-container (~> 0.6)
dry-equalizer (~> 0.2)
inflecto (>= 0.0.2)
dry-types (0.9.4)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.1)
Expand Down Expand Up @@ -222,6 +231,7 @@ DEPENDENCIES
capybara
connection_pool
dotenv (~> 2.0)
dry-system
hanami (= 1.0.0)
hanami-bootstrap (= 0.4)
hanami-model (= 1.0.0)
Expand Down
6 changes: 6 additions & 0 deletions config/initializers/application.rb
@@ -0,0 +1,6 @@
require 'dry/system/container'

class Application < Dry::System::Container
configure do |config|
end
end
8 changes: 0 additions & 8 deletions config/initializers/redis.rb

This file was deleted.

4 changes: 2 additions & 2 deletions config/initializers/sidekiq.rb
@@ -1,9 +1,9 @@
require 'sidekiq-scheduler'

Sidekiq.configure_server do |config|
config.redis = REDIS
config.redis = Application[:redis]
end

Sidekiq.configure_client do |config|
config.redis = REDIS
config.redis = Application[:redis]
end
14 changes: 14 additions & 0 deletions system/boot/redis.rb
@@ -0,0 +1,14 @@
Application.finalize(:redis) do |container|
init do
if Hanami.env?(:production)
uri = URI.parse(ENV.fetch("REDISTOGO_URL"))
redis = ConnectionPool.new(size: 10, timeout: 3) { Redis.new(driver: :hiredis, host: uri.host, port: uri.port, password: uri.password) }
elsif Hanami.env?(:test)
redis = ConnectionPool.new(size: 10, timeout: 3) { MockRedis.new }
else
redis = ConnectionPool.new(size: 10, timeout: 3) { Redis.new(host: 'localhost', port: 6379) }
end

container.register(:redis, redis)
end
end
2 changes: 2 additions & 0 deletions system/import.rb
@@ -0,0 +1,2 @@
require 'system/container'
Import = Application.injector

0 comments on commit 2a62c83

Please sign in to comment.