Class: Shakapacker::DevServer
- Inherits:
-
Object
- Object
- Shakapacker::DevServer
- Defined in:
- lib/shakapacker/dev_server.rb
Constant Summary collapse
- DEFAULT_ENV_PREFIX =
"SHAKAPACKER_DEV_SERVER".freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #env_prefix ⇒ Object
- #hmr? ⇒ Boolean
- #host ⇒ Object
- #host_with_port ⇒ Object
-
#initialize(config) ⇒ DevServer
constructor
A new instance of DevServer.
- #inline_css? ⇒ Boolean
- #port ⇒ Object
- #pretty? ⇒ Boolean
- #protocol ⇒ Object
- #running? ⇒ Boolean
- #server ⇒ Object
Constructor Details
#initialize(config) ⇒ DevServer
Returns a new instance of DevServer.
10 11 12 |
# File 'lib/shakapacker/dev_server.rb', line 10 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/shakapacker/dev_server.rb', line 8 def config @config end |
Instance Method Details
#env_prefix ⇒ Object
79 80 81 |
# File 'lib/shakapacker/dev_server.rb', line 79 def env_prefix config.dev_server.fetch(:env_prefix, DEFAULT_ENV_PREFIX) end |
#hmr? ⇒ Boolean
66 67 68 |
# File 'lib/shakapacker/dev_server.rb', line 66 def hmr? fetch(:hmr) end |
#host ⇒ Object
25 26 27 |
# File 'lib/shakapacker/dev_server.rb', line 25 def host fetch(:host) end |
#host_with_port ⇒ Object
58 59 60 |
# File 'lib/shakapacker/dev_server.rb', line 58 def host_with_port "#{host}:#{port}" end |
#inline_css? ⇒ Boolean
70 71 72 73 74 75 76 77 |
# File 'lib/shakapacker/dev_server.rb', line 70 def inline_css? case fetch(:inline_css) when false, "false" false else true end end |
#port ⇒ Object
29 30 31 |
# File 'lib/shakapacker/dev_server.rb', line 29 def port fetch(:port) end |
#pretty? ⇒ Boolean
62 63 64 |
# File 'lib/shakapacker/dev_server.rb', line 62 def pretty? fetch(:pretty) end |
#protocol ⇒ Object
52 53 54 55 56 |
# File 'lib/shakapacker/dev_server.rb', line 52 def protocol return "https" if server == "https" "http" end |
#running? ⇒ Boolean
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/shakapacker/dev_server.rb', line 14 def running? if config.dev_server.present? Socket.tcp(host, port, connect_timeout: connect_timeout).close true else false end rescue false end |
#server ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/shakapacker/dev_server.rb', line 33 def server server_value = fetch(:server) server_type = server_value.is_a?(Hash) ? server_value[:type] : server_value return server_type if ["http", "https"].include?(server_type) return "http" if server_type.nil? puts <<~MSG WARNING: `server: #{server_type}` is not a valid configuration in Shakapacker. Falling back to default `server: http`. MSG "http" rescue KeyError "http" end |