Class: Tzispa::Environment
- Inherits:
-
Object
- Object
- Tzispa::Environment
- Includes:
- Singleton
- Defined in:
- lib/tzispa/environment.rb
Constant Summary collapse
- LOCK =
Mutex.new
- RACK_ENV =
'RACK_ENV'- TZISPA_ENV =
'TZISPA_ENV'- DEVELOPMENT_ENV =
'development'- DEFAULT_ENV =
'development'- PRODUCTION_ENV =
'deployment'- RACK_ENV_DEPLOYMENT =
'deployment'- DEFAULT_DOTENV_ENV =
'.env.%s'- DEFAULT_CONFIG =
'config'- TZISPA_HOST =
'TZISPA_HOST'- TZISPA_SSL =
'TZISPA_SSL'- TZISPA_SERVER_HOST =
'TZISPA_SERVER_HOST'- DEFAULT_HOST =
'localhost'- TZISPA_PORT =
'TZISPA_PORT'- TZISPA_SERVER_PORT =
'TZISPA_SERVER_PORT'- DEFAULT_PORT =
9412- DEFAULT_RACKUP =
'tzispa.ru'- DEFAULT_ENVIRONMENT_CONFIG =
'environment'- DEFAULT_DOMAINS_PATH =
'apps'- DOMAINS =
'domains'- DOMAINS_PATH =
'apps/%s'- APPLICATION =
'application'- APPLICATION_PATH =
'app'- @@opts =
rubocop:disable Style/ClassVars
{}
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #apps_path ⇒ Object
- #architecture ⇒ Object
- #bundler_groups ⇒ Object
- #code_reloading? ⇒ Boolean
- #config ⇒ Object
- #daemonize? ⇒ Boolean
- #default_port? ⇒ Boolean
- #development? ⇒ Boolean
- #domains_path ⇒ Object
- #environment ⇒ Object
- #environment?(*names) ⇒ Boolean
- #host ⇒ Object
-
#initialize ⇒ Environment
constructor
A new instance of Environment.
- #port ⇒ Object
- #project_name ⇒ Object
- #rackup ⇒ Object
- #root ⇒ Object
- #server_host ⇒ Object
- #server_port ⇒ Object
- #ssl? ⇒ Boolean
- #to_options ⇒ Object
- #uri_port ⇒ Object
Constructor Details
#initialize ⇒ Environment
Returns a new instance of Environment.
65 66 67 68 69 70 |
# File 'lib/tzispa/environment.rb', line 65 def initialize @env = Tzispa::Env.new(env: @@opts.delete(:env) || ENV) = Tzispa::Tzisparc.new(root). .merge! @@opts.clone.symbolize! LOCK.synchronize { set_env_vars! } end |
Class Method Details
.[](key) ⇒ Object
76 77 78 |
# File 'lib/tzispa/environment.rb', line 76 def self.[](key) instance[key] end |
.development? ⇒ Boolean
80 81 82 |
# File 'lib/tzispa/environment.rb', line 80 def self.development? instance.development? end |
.opts=(hash) ⇒ Object
72 73 74 |
# File 'lib/tzispa/environment.rb', line 72 def self.opts=(hash) @@opts = hash.to_h.dup end |
Instance Method Details
#[](key) ⇒ Object
84 85 86 |
# File 'lib/tzispa/environment.rb', line 84 def [](key) @env[key] end |
#apps_path ⇒ Object
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/tzispa/environment.rb', line 123 def apps_path .fetch(:path) do case architecture when DOMAINS DOMAINS_PATH when APPLICATION APPLICATION_PATH end end end |
#architecture ⇒ Object
112 113 114 115 116 117 |
# File 'lib/tzispa/environment.rb', line 112 def architecture .fetch(:architecture) do puts "Tzispa architecture unknown: see `.tzisparc'" exit 1 end end |
#bundler_groups ⇒ Object
104 105 106 |
# File 'lib/tzispa/environment.rb', line 104 def bundler_groups [:default, environment.to_sym] end |
#code_reloading? ⇒ Boolean
96 97 98 |
# File 'lib/tzispa/environment.rb', line 96 def code_reloading? development? end |
#config ⇒ Object
134 135 136 |
# File 'lib/tzispa/environment.rb', line 134 def config @config ||= root.join(.fetch(:config) { DEFAULT_CONFIG }) end |
#daemonize? ⇒ Boolean
188 189 190 |
# File 'lib/tzispa/environment.rb', line 188 def daemonize? .key?(:daemonize) && .fetch(:daemonize) end |
#default_port? ⇒ Boolean
176 177 178 |
# File 'lib/tzispa/environment.rb', line 176 def default_port? port == DEFAULT_PORT end |
#development? ⇒ Boolean
92 93 94 |
# File 'lib/tzispa/environment.rb', line 92 def development? environment == DEVELOPMENT_ENV end |
#domains_path ⇒ Object
170 171 172 173 174 |
# File 'lib/tzispa/environment.rb', line 170 def domains_path @domains_path ||= .fetch(:domains_path) do env[DOMAINS_PATH] || DEFAULT_DOMAINS_PATH end end |
#environment ⇒ Object
88 89 90 |
# File 'lib/tzispa/environment.rb', line 88 def environment @environment ||= env[TZISPA_ENV] || rack_env || DEFAULT_ENV end |
#environment?(*names) ⇒ Boolean
100 101 102 |
# File 'lib/tzispa/environment.rb', line 100 def environment?(*names) names.map(&:to_s).include?(environment) end |
#host ⇒ Object
138 139 140 141 142 |
# File 'lib/tzispa/environment.rb', line 138 def host @host ||= .fetch(:host) do env[TZISPA_HOST] || DEFAULT_HOST end end |
#port ⇒ Object
150 151 152 153 154 |
# File 'lib/tzispa/environment.rb', line 150 def port @port ||= .fetch(:port) do env[TZISPA_PORT] || DEFAULT_PORT end.to_i end |
#project_name ⇒ Object
108 109 110 |
# File 'lib/tzispa/environment.rb', line 108 def project_name .fetch(:project) end |
#rackup ⇒ Object
184 185 186 |
# File 'lib/tzispa/environment.rb', line 184 def rackup root.join(.fetch(:rackup) { DEFAULT_RACKUP }) end |
#root ⇒ Object
119 120 121 |
# File 'lib/tzispa/environment.rb', line 119 def root @root ||= Pathname.new(Dir.pwd) end |
#server_host ⇒ Object
144 145 146 147 148 |
# File 'lib/tzispa/environment.rb', line 144 def server_host @server_host ||= .fetch(:server_host) do env[TZISPA_SERVER_HOST] || host end end |
#server_port ⇒ Object
156 157 158 159 160 |
# File 'lib/tzispa/environment.rb', line 156 def server_port @server_port ||= .fetch(:server_port) do env[TZISPA_SERVER_PORT] || port end.to_i end |
#ssl? ⇒ Boolean
180 181 182 |
# File 'lib/tzispa/environment.rb', line 180 def ssl? env[TZISPA_SSL] == 'yes' end |
#to_options ⇒ Object
192 193 194 195 196 197 198 199 200 |
# File 'lib/tzispa/environment.rb', line 192 def .to_h.merge( environment: environment, apps_path: apps_path, rackup: rackup, host: server_host, port: server_port ) end |
#uri_port ⇒ Object
162 163 164 165 166 167 168 |
# File 'lib/tzispa/environment.rb', line 162 def uri_port if ssl? ":#{port}" unless port == 443 else ":#{port}" unless port == 80 end end |