Class: Device::Setting

Inherits:
Object
  • Object
show all
Defined in:
lib/device/setting.rb

Constant Summary collapse

FILE_PATH =
"./main/config.dat"
HOST_PRODUCTION =
"switch.cloudwalk.io"
HOST_STAGING =
"switch-staging.cloudwalk.io"
PORT_TCP =
"31415"
PORT_TCP_SSL =
"31416"
DEFAULT =
{
  "host"                        => HOST_PRODUCTION,
  "host_port"                   => PORT_TCP_SSL,
  "ssl"                         => "1",
  "user"                        => "",
  "password"                    => "", #WIFI
  "apn"                         => "",
  "authentication"              => "", #WIFI
  "essid"                       => "", #WIFI
  "bssid"                       => "", #WIFI
  "cipher"                      => "", #WIFI
  "mode"                        => "", #WIFI
  "channel"                     => "", #WIFI
  "media"                       => "",
  "ip"                          => "",
  "gateway"                     => "",
  "dns1"                        => "",
  "dns2"                        => "",
  "subnet"                      => "",
  "logical_number"              => "",
  "network_configured"          => "",
  "environment"                 => "",
  "notification_timeout"        => "",
  "notification_interval"       => "",
  "notification_stream_timeout" => "",
  "cw_switch_version"           => "",
  "cw_pos_timezone"             => "",
  "uclreceivetimeout"           => "0",
  "iso8583_recv_tries"          => "0",
  "company_name"                => ""
}

Class Method Summary collapse

Class Method Details

.check_environment!Object



48
49
50
51
52
53
54
# File 'lib/device/setting.rb', line 48

def self.check_environment!
  if self.staging?
    self.to_staging!
  else
    self.to_production!
  end
end

.method_missing(method, *args, &block) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/device/setting.rb', line 72

def self.method_missing(method, *args, &block)
  setup unless @file
  param = method.to_s
  if @file[param]
    @file[param]
  elsif (param[-1..-1] == "=" && @file[param[0..-2]])
    @file[param[0..-2]] = args.first
  else
    super
  end
end

.production?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/device/setting.rb', line 56

def self.production?
  self.environment == "production"
end

.setupObject



42
43
44
45
46
# File 'lib/device/setting.rb', line 42

def self.setup
  @file = FileDb.new(FILE_PATH, DEFAULT)
  self.check_environment!
  @file
end

.staging?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/device/setting.rb', line 60

def self.staging?
  self.environment == "staging"
end

.to_production!Object



64
65
66
# File 'lib/device/setting.rb', line 64

def self.to_production!
  self.host = HOST_PRODUCTION
end

.to_staging!Object



68
69
70
# File 'lib/device/setting.rb', line 68

def self.to_staging!
  self.host = HOST_STAGING
end