Class: Dovado::Router::Internet

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/dovado/router/internet.rb

Overview

Internet Connection.

Since:

  • 1.0.3

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInternet

Create a new Dovado::Router::Internet object.

Since:

  • 1.0.3



10
11
12
13
# File 'lib/dovado/router/internet.rb', line 10

def initialize
  @state = ThreadSafe::Cache.new
  @state[:status] = :offline
end

Class Method Details

.setup_supervision!Object

Since:

  • 1.0.3



61
62
63
# File 'lib/dovado/router/internet.rb', line 61

def self.setup_supervision!
  supervise as: :internet, size: 1 unless Actor[:internet]
end

Instance Method Details

#off!Object

Disable internet connection.

Since:

  • 1.0.3



25
26
27
28
29
30
31
# File 'lib/dovado/router/internet.rb', line 25

def off!
  client = Actor[:client]
  client.connect unless client.connected?
  client.authenticate unless client.authenticated?
  client.command("internet off")
  status = :offline
end

#off?Boolean

Check if the internet connection is down.

Returns:

  • (Boolean)

    true if internet was disabled, false otherwise.

Since:

  • 1.0.3



43
44
45
# File 'lib/dovado/router/internet.rb', line 43

def off?
  status == :offline
end

#on!Object

Enable internet connection.

Since:

  • 1.0.3



16
17
18
19
20
21
22
# File 'lib/dovado/router/internet.rb', line 16

def on!
  client = Actor[:client]
  client.connect unless client.connected?
  client.authenticate unless client.authenticated?
  client.command("internet on")
  status = :online
end

#on?Boolean

Check if the internet connection is up.

Returns:

  • (Boolean)

    true if internet was enabled, false otherwise.

Since:

  • 1.0.3



36
37
38
# File 'lib/dovado/router/internet.rb', line 36

def on?
  status == :online
end

#statusSymbol

Return the current status of the internet connection.

Returns:

  • (Symbol)

    one of: :online or :offline

Since:

  • 1.0.3



50
51
52
# File 'lib/dovado/router/internet.rb', line 50

def status
  @state[:status]
end

#status=(value) ⇒ Object

Set the current status of the internet connection.

Parameters:

  • value (Symbol)

    one of: :online or :offline

Since:

  • 1.0.3



57
58
59
# File 'lib/dovado/router/internet.rb', line 57

def status=(value)
  @state[:status] = value
end