Class: Whoosh::Config

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

Constant Summary collapse

DEFAULTS =
{
  "app" => {
    "name" => "Whoosh App",
    "env" => "development",
    "port" => 9292,
    "host" => "localhost"
  },
  "server" => {
    "type" => "falcon",
    "workers" => "auto",
    "timeout" => 30
  },
  "logging" => {
    "level" => "info",
    "format" => "json"
  },
  "docs" => {
    "enabled" => true
  },
  "performance" => {
    "yjit" => true,
    "yjit_exec_mem" => 64
  }
}.freeze
ENV_MAP =
{
  "WHOOSH_PORT" => ["app", "port"],
  "WHOOSH_HOST" => ["app", "host"],
  "WHOOSH_ENV" => ["app", "env"],
  "WHOOSH_LOG_LEVEL" => ["logging", "level"],
  "WHOOSH_LOG_FORMAT" => ["logging", "format"]
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root:) ⇒ Config

Returns a new instance of Config.



48
49
50
51
52
53
54
55
# File 'lib/whoosh/config.rb', line 48

def initialize(root:)
  @data = deep_dup(DEFAULTS)
  @root = root
  @json_engine = :json

  load_yaml
  apply_env
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



42
43
44
# File 'lib/whoosh/config.rb', line 42

def data
  @data
end

#json_engineObject

Returns the value of attribute json_engine.



41
42
43
# File 'lib/whoosh/config.rb', line 41

def json_engine
  @json_engine
end

Class Method Details

.load(root:) ⇒ Object



44
45
46
# File 'lib/whoosh/config.rb', line 44

def self.load(root:)
  new(root: root)
end

Instance Method Details

#app_nameObject



77
78
79
# File 'lib/whoosh/config.rb', line 77

def app_name
  @data.dig("app", "name")
end

#development?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/whoosh/config.rb', line 101

def development?
  env == "development"
end

#docs_enabled?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/whoosh/config.rb', line 93

def docs_enabled?
  @data.dig("docs", "enabled")
end

#envObject



73
74
75
# File 'lib/whoosh/config.rb', line 73

def env
  @data.dig("app", "env")
end

#hostObject



65
66
67
# File 'lib/whoosh/config.rb', line 65

def host
  @data.dig("app", "host")
end

#host=(value) ⇒ Object



69
70
71
# File 'lib/whoosh/config.rb', line 69

def host=(value)
  @data["app"]["host"] = value
end

#log_formatObject



89
90
91
# File 'lib/whoosh/config.rb', line 89

def log_format
  @data.dig("logging", "format")
end

#log_levelObject



85
86
87
# File 'lib/whoosh/config.rb', line 85

def log_level
  @data.dig("logging", "level")
end

#portObject



57
58
59
# File 'lib/whoosh/config.rb', line 57

def port
  @data.dig("app", "port")
end

#port=(value) ⇒ Object



61
62
63
# File 'lib/whoosh/config.rb', line 61

def port=(value)
  @data["app"]["port"] = value.to_i
end

#production?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/whoosh/config.rb', line 105

def production?
  env == "production"
end

#server_typeObject



81
82
83
# File 'lib/whoosh/config.rb', line 81

def server_type
  @data.dig("server", "type")
end

#shutdown_timeoutObject



97
98
99
# File 'lib/whoosh/config.rb', line 97

def shutdown_timeout
  @data.dig("server", "timeout") || 30
end

#test?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/whoosh/config.rb', line 109

def test?
  env == "test"
end