Created
April 18, 2018 23:45
-
-
Save dmaze/308034415354fb0ec2e537157b3a39b8 to your computer and use it in GitHub Desktop.
A dry-system application that uses an environment variable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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