Class: Puma::LeveledOptions

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(default_options, user_options) ⇒ LeveledOptions

Returns a new instance of LeveledOptions.



16
17
18
19
20
# File 'lib/puma/configuration.rb', line 16

def initialize(default_options, user_options)
  @cur = user_options
  @set = [@cur]
  @defaults = default_options.dup
end

Instance Attribute Details

#curObject (readonly)

Returns the value of attribute cur.



53
54
55
# File 'lib/puma/configuration.rb', line 53

def cur
  @cur
end

Instance Method Details

#[](key) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/puma/configuration.rb', line 32

def [](key)
  @set.each do |o|
    if o.key? key
      return o[key]
    end
  end

  v = @defaults[key]
  if v.respond_to? :call
    v.call
  else
    v
  end
end

#[]=(key, val) ⇒ Object



71
72
73
# File 'lib/puma/configuration.rb', line 71

def []=(key, val)
  @cur[key] = val
end

#all_of(key) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/puma/configuration.rb', line 55

def all_of(key)
  all = []

  @set.each do |o|
    if v = o[key]
      if v.kind_of? Array
        all += v
      else
        all << v
      end
    end
  end

  all
end

#explainObject



103
104
105
106
107
108
109
110
111
112
113
# File 'lib/puma/configuration.rb', line 103

def explain
  indent = ""

  @set.each do |o|
    o.keys.sort.each do |k|
      puts "#{indent}#{k}: #{o[k].inspect}"
    end

    indent = "  #{indent}"
  end
end

#fetch(key, default = nil) ⇒ Object



47
48
49
50
51
# File 'lib/puma/configuration.rb', line 47

def fetch(key, default=nil)
  val = self[key]
  return val if val
  default
end

#flattenObject



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/puma/configuration.rb', line 91

def flatten
  options = {}

  @set.each do |o|
    o.each do |k,v|
      options[k] ||= v
    end
  end

  options
end

#force_defaultsObject



115
116
117
118
119
120
121
# File 'lib/puma/configuration.rb', line 115

def force_defaults
  @defaults.each do |k,v|
    if v.respond_to? :call
      @defaults[k] = v.call
    end
  end
end

#initialize_copy(other) ⇒ Object



22
23
24
25
# File 'lib/puma/configuration.rb', line 22

def initialize_copy(other)
  @set = @set.map { |o| o.dup }
  @cur = @set.last
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
78
79
80
81
82
83
# File 'lib/puma/configuration.rb', line 75

def key?(key)
  @set.each do |o|
    if o.key? key
      return true
    end
  end

  @default.key? key
end

#merge!(o) ⇒ Object



85
86
87
88
89
# File 'lib/puma/configuration.rb', line 85

def merge!(o)
  o.each do |k,v|
    @cur[k]= v
  end
end

#shiftObject



27
28
29
30
# File 'lib/puma/configuration.rb', line 27

def shift
  @cur = {}
  @set << @cur
end