Class: Loadout::Config

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

Instance Method Summary collapse

Constructor Details

#initialize(env, creds) ⇒ Config

Returns a new instance of Config.



37
38
39
40
41
42
43
44
# File 'lib/loadout.rb', line 37

def initialize(env, creds)
  @env = env
  @creds = creds
  @type = nil
  @prefix_stack = []
  @lookup_list = Set[]
  @prefix_default = NONE
end

Instance Method Details

#boolObject



64
# File 'lib/loadout.rb', line 64

def bool                         = dup.tap { _1.type = :bool }

#cred(*keys, &default) ⇒ Object



52
53
54
55
56
# File 'lib/loadout.rb', line 52

def cred(*keys, &default)
  return dup.tap { _1.lookup_list << :cred } if keys.empty?
  @lookup_list << :cred
  lookup(keys, &default)
end

#env(*keys, &default) ⇒ Object



46
47
48
49
50
# File 'lib/loadout.rb', line 46

def env(*keys, &default)
  return dup.tap { _1.lookup_list << :env } if keys.empty?
  @lookup_list << :env
  lookup(keys, &default)
end

#floatObject



66
# File 'lib/loadout.rb', line 66

def float                        = dup.tap { _1.type = :float }

#initialize_dup(other) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/loadout.rb', line 69

def initialize_dup(other)
  @type         = other.instance_variable_get(:@type).dup
  @prefix_stack = other.instance_variable_get(:@prefix_stack).dup
  @lookup_list  = other.instance_variable_get(:@lookup_list).dup

  unless other.instance_variable_get(:@prefix_default).equal?(NONE)
    @prefix_default = other.instance_variable_get(:@prefix_default).dup
  end

  super
end

#intObject



65
# File 'lib/loadout.rb', line 65

def int                          = dup.tap { _1.type = :int }

#list(sep = DEFAULT_LIST_SEP) ⇒ Object



67
# File 'lib/loadout.rb', line 67

def list(sep = DEFAULT_LIST_SEP) = dup.tap { _1.type = [:list, sep] }

#prefix(*keys, default: NONE) ⇒ Object



58
59
60
61
62
# File 'lib/loadout.rb', line 58

def prefix(*keys, default: NONE)
  @prefix_default = default unless default.equal?(NONE)
  @prefix_stack.push(keys)
  yield.tap { @prefix_stack.pop }
end