Class: Webpacker::DevServer

Inherits:
Object
  • Object
show all
Defined in:
lib/webpacker/dev_server.rb

Constant Summary collapse

DEFAULT_ENV_PREFIX =
"WEBPACKER_DEV_SERVER".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ DevServer

Returns a new instance of DevServer.



10
11
12
# File 'lib/webpacker/dev_server.rb', line 10

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/webpacker/dev_server.rb', line 8

def config
  @config
end

Instance Method Details

#env_prefixObject



54
55
56
# File 'lib/webpacker/dev_server.rb', line 54

def env_prefix
  config.dev_server.fetch(:env_prefix, DEFAULT_ENV_PREFIX)
end

#hostObject



25
26
27
# File 'lib/webpacker/dev_server.rb', line 25

def host
  fetch(:host)
end

#host_with_portObject



46
47
48
# File 'lib/webpacker/dev_server.rb', line 46

def host_with_port
  "#{host}:#{port}"
end

#https?Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
# File 'lib/webpacker/dev_server.rb', line 33

def https?
  case fetch(:https)
  when true, "true", Hash
    true
  else
    false
  end
end

#portObject



29
30
31
# File 'lib/webpacker/dev_server.rb', line 29

def port
  fetch(:port)
end

#pretty?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/webpacker/dev_server.rb', line 50

def pretty?
  fetch(:pretty)
end

#protocolObject



42
43
44
# File 'lib/webpacker/dev_server.rb', line 42

def protocol
  https? ? "https" : "http"
end

#running?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
# File 'lib/webpacker/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