class Device::Setting

Constants

DEFAULT
FILE_PATH
HOST_PRODUCTION
HOST_STAGING
HTTP_HOST_PRODUCTION
HTTP_HOST_STAGING
HTTP_PORT
PORT_TCP
PORT_TCP_SSL

Attributes

file[RW]

Public Class Methods

attach_gprs_timeout() click to toggle source
# File lib/device/setting.rb, line 158
def self.attach_gprs_timeout
  value = (DaFunk::ParamsDat.file["attach_gprs_timeout"] || @file&.dig("attach_gprs_timeout"))
  value.to_s.empty? ? nil : value.to_s.to_i
end
check_environment!() click to toggle source
# File lib/device/setting.rb, line 89
def self.check_environment!
  if self.staging?
    self.to_staging!
  else
    self.to_production!
  end
end
heartbeat() click to toggle source
# File lib/device/setting.rb, line 163
def self.heartbeat
  DaFunk::ParamsDat.file["heartbeat"] || @file&.dig("heartbeat")
end
logical_number() click to toggle source
# File lib/device/setting.rb, line 167
def self.logical_number
  if self.file["logical_number"].to_s.strip.empty?
    self.file["logical_number"] = Device::System.serial
  else
    self.file["logical_number"]
  end
end
method_missing(method, *args, &block) click to toggle source
Calls superclass method
# File lib/device/setting.rb, line 125
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
payment_channel_set_attempts(time = nil, attempts = nil) click to toggle source

helper

# File lib/device/setting.rb, line 138
def self.payment_channel_set_attempts(time = nil, attempts = nil)
  setup
  if time
    str = "%d-%02d-%02d"
    update_attributes({
      "payment_channel_date"     => (str % [time.year, time.mon, time.day]),
      "payment_channel_attempts" => (attempts || 1)
    })
  else
    update_attributes({
      "payment_channel_attempts" => (attempts || 1)
    })
  end
end
production?() click to toggle source
# File lib/device/setting.rb, line 97
def self.production?
  self.environment == "production"
end
setup() click to toggle source
# File lib/device/setting.rb, line 83
def self.setup
  @file = FileDb.new(FILE_PATH, DEFAULT)
  self.check_environment!
  @file
end
staging?() click to toggle source
# File lib/device/setting.rb, line 101
def self.staging?
  self.environment == "staging"
end
tcp_recv_timeout() click to toggle source

Custom Attributes

# File lib/device/setting.rb, line 154
def self.tcp_recv_timeout
  DaFunk::ParamsDat.file["tcp_recv_timeout"] || @file&.dig("tcp_recv_timeout")
end
to_production!() click to toggle source
# File lib/device/setting.rb, line 105
def self.to_production!
  if self.environment != "production"
    @file.update_attributes("company_name" => "", "environment" => "production", "host" => HOST_PRODUCTION, "transaction_http_host" => HTTP_HOST_PRODUCTION)
    return true
  end
  false
end
to_staging!() click to toggle source
# File lib/device/setting.rb, line 113
def self.to_staging!
  if self.environment != "staging"
    @file.update_attributes("company_name" => "", "environment" => "staging", "host" => HOST_STAGING, "transaction_http_host" => HTTP_HOST_STAGING)
    return true
  end
  false
end
update_attributes(*args) click to toggle source
# File lib/device/setting.rb, line 121
def self.update_attributes(*args)
  @file.update_attributes(*args)
end