Class: ENVV::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/envv/builder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env, schema) ⇒ Builder

Returns a new instance of Builder.



20
21
22
23
# File 'lib/envv/builder.rb', line 20

def initialize(env, schema)
  @env = env
  @schema = schema
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



8
9
10
# File 'lib/envv/builder.rb', line 8

def env
  @env
end

#schemaObject (readonly)

Returns the value of attribute schema.



8
9
10
# File 'lib/envv/builder.rb', line 8

def schema
  @schema
end

Class Method Details

.call(env, schema = nil) ⇒ Object



11
12
13
# File 'lib/envv/builder.rb', line 11

def call(env, schema = nil)
  new(env, schema).call
end

.to_procObject



15
16
17
# File 'lib/envv/builder.rb', line 15

def to_proc
  method(:call).to_proc
end

Instance Method Details

#callObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/envv/builder.rb', line 25

def call
  validate_params!
  result = @schema.call(extract_env_vars)

  if result.failure?
    raise ValidationError, result.errors(full: true).to_h.values.flatten
  else
    ENVV::Registry[result.to_h.transform_keys(&:to_s)].freeze
  end
end