Class: Tzispa::Environment
Constant Summary
collapse
- LOCK =
Mutex.new
- @@opts =
rubocop:disable Style/ClassVars
{}
Config::Environment::APPLICATION, Config::Environment::APPLICATION_PATH, Config::Environment::DEFAULT_CONFIG, Config::Environment::DEFAULT_DOMAINS_PATH, Config::Environment::DEFAULT_DOTENV_ENV, Config::Environment::DEFAULT_ENV, Config::Environment::DEFAULT_ENVIRONMENT_CONFIG, Config::Environment::DEFAULT_HOST, Config::Environment::DEFAULT_PORT, Config::Environment::DEFAULT_RACKUP, Config::Environment::DEVELOPMENT_ENV, Config::Environment::DOMAINS, Config::Environment::DOMAINS_PATH, Config::Environment::PRODUCTION_ENV, Config::Environment::RACK_ENV, Config::Environment::RACK_ENV_DEPLOYMENT, Config::Environment::TZISPA_ENV, Config::Environment::TZISPA_HOST, Config::Environment::TZISPA_PORT, Config::Environment::TZISPA_SERVER_HOST, Config::Environment::TZISPA_SERVER_PORT, Config::Environment::TZISPA_SSL
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Environment.
23
24
25
26
27
28
|
# File 'lib/tzispa/environment.rb', line 23
def initialize
@env = Tzispa::Env.new(env: @@opts.delete(:env) || ENV)
@options = Tzispa::Tzisparc.new(root).options
@options.merge! @@opts.clone.symbolize!
LOCK.synchronize { set_env_vars! }
end
|
Class Method Details
.[](key) ⇒ Object
35
36
37
|
# File 'lib/tzispa/environment.rb', line 35
def [](key)
instance[key]
end
|
.method_missing(name, *args, &block) ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'lib/tzispa/environment.rb', line 39
def method_missing(name, *args, &block)
if instance.respond_to? name
instance.send name, *args, &block
elsif instance.key? ekup = name.to_s.upcase
instance[ekup]
else
super
end
end
|
.opts=(hash) ⇒ Object
31
32
33
|
# File 'lib/tzispa/environment.rb', line 31
def opts=(hash)
@@opts = hash.to_h.dup
end
|
Instance Method Details
#[](key) ⇒ Object
50
51
52
|
# File 'lib/tzispa/environment.rb', line 50
def [](key)
@env[key]
end
|
#architecture ⇒ Object
90
91
92
93
94
95
|
# File 'lib/tzispa/environment.rb', line 90
def architecture
@options.fetch(:architecture) do
warn "Tzispa architecture unknown: see `.tzisparc'"
exit 1
end
end
|
#bundler_groups ⇒ Object
74
75
76
|
# File 'lib/tzispa/environment.rb', line 74
def bundler_groups
[:default, environment.to_sym]
end
|
#code_reloading? ⇒ Boolean
66
67
68
|
# File 'lib/tzispa/environment.rb', line 66
def code_reloading?
development?
end
|
#config ⇒ Object
82
83
84
|
# File 'lib/tzispa/environment.rb', line 82
def config
@config ||= root.join(@options.fetch(:config) { DEFAULT_CONFIG })
end
|
#daemonize? ⇒ Boolean
158
159
160
|
# File 'lib/tzispa/environment.rb', line 158
def daemonize?
@options.key?(:daemonize) && @options.fetch(:daemonize)
end
|
#default_port? ⇒ Boolean
146
147
148
|
# File 'lib/tzispa/environment.rb', line 146
def default_port?
port == DEFAULT_PORT
end
|
#development? ⇒ Boolean
62
63
64
|
# File 'lib/tzispa/environment.rb', line 62
def development?
environment == DEVELOPMENT_ENV
end
|
#domains_path ⇒ Object
140
141
142
143
144
|
# File 'lib/tzispa/environment.rb', line 140
def domains_path
@domains_path ||= @options.fetch(:domains_path) do
env[DOMAINS_PATH] || DEFAULT_DOMAINS_PATH
end
end
|
#environment ⇒ Object
58
59
60
|
# File 'lib/tzispa/environment.rb', line 58
def environment
@environment ||= env[TZISPA_ENV] || rack_env || DEFAULT_ENV
end
|
#environment?(*names) ⇒ Boolean
70
71
72
|
# File 'lib/tzispa/environment.rb', line 70
def environment?(*names)
names.map(&:to_s).include?(environment)
end
|
#host ⇒ Object
108
109
110
111
112
|
# File 'lib/tzispa/environment.rb', line 108
def host
@host ||= @options.fetch(:host) do
env[TZISPA_HOST] || DEFAULT_HOST
end
end
|
#key?(key) ⇒ Boolean
54
55
56
|
# File 'lib/tzispa/environment.rb', line 54
def key?(key)
@env.key? key
end
|
#port ⇒ Object
120
121
122
123
124
|
# File 'lib/tzispa/environment.rb', line 120
def port
@port ||= @options.fetch(:port) do
env[TZISPA_PORT] || DEFAULT_PORT
end.to_i
end
|
#project_name ⇒ Object
86
87
88
|
# File 'lib/tzispa/environment.rb', line 86
def project_name
@options.fetch(:project)
end
|
#rackup ⇒ Object
154
155
156
|
# File 'lib/tzispa/environment.rb', line 154
def rackup
root.join(@options.fetch(:rackup) { DEFAULT_RACKUP })
end
|
#root ⇒ Object
78
79
80
|
# File 'lib/tzispa/environment.rb', line 78
def root
@root ||= Pathname.new(Dir.pwd)
end
|
#server_host ⇒ Object
114
115
116
117
118
|
# File 'lib/tzispa/environment.rb', line 114
def server_host
@server_host ||= @options.fetch(:server_host) do
env[TZISPA_SERVER_HOST] || host
end
end
|
#server_port ⇒ Object
126
127
128
129
130
|
# File 'lib/tzispa/environment.rb', line 126
def server_port
@server_port ||= @options.fetch(:server_port) do
env[TZISPA_SERVER_PORT] || port
end.to_i
end
|
#ssl? ⇒ Boolean
150
151
152
|
# File 'lib/tzispa/environment.rb', line 150
def ssl?
env[TZISPA_SSL] == 'yes'
end
|
#to_options ⇒ Object
162
163
164
165
166
167
168
169
170
|
# File 'lib/tzispa/environment.rb', line 162
def to_options
@options.to_h.merge(
environment: environment,
apps_path: apps_path,
rackup: rackup,
host: server_host,
port: server_port
)
end
|
#uri_port ⇒ Object
132
133
134
135
136
137
138
|
# File 'lib/tzispa/environment.rb', line 132
def uri_port
if ssl?
":#{port}" unless port == 443
else
":#{port}" unless port == 80
end
end
|