Skip to content

Instantly share code, notes, and snippets.

@dmaze
Created April 18, 2018 23:45
Show Gist options
  • Save dmaze/308034415354fb0ec2e537157b3a39b8 to your computer and use it in GitHub Desktop.
Save dmaze/308034415354fb0ec2e537157b3a39b8 to your computer and use it in GitHub Desktop.
A dry-system application that uses an environment variable
# frozen_string_literal: true
require 'dry/system/container'
require 'dry/system/components'
require 'dry/types'
module Types
include Dry::Types.module
end
class Application < Dry::System::Container
use(:env)
boot(:settings, from: :system) do
settings do
key :an_int, Types::Coercible::Int.default(17)
end
end
end
Import = Application.injector
class Main
include Import['settings']
def call
puts "The magic number is #{settings.an_int}"
end
end
Main.new.()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment