Class: Terminal
- Inherits:
-
Object
- Object
- Terminal
- Includes:
- Redis::Objects
- Defined in:
- app/models/terminal.rb
Class Method Summary collapse
- .actual_modified_at ⇒ Object
- .as_json(*args) ⇒ Object
- .condition ⇒ Object
-
.config ⇒ Object
CONDITON.
- .disable ⇒ Object
-
.enable ⇒ Object
STATES.
- .enabled? ⇒ Boolean
- .ip ⇒ Object
- .keyword ⇒ Object
- .payment_in_progress? ⇒ Boolean
-
.ping ⇒ Object
ACTIONS.
- .providers_updated_at ⇒ Object
- .providers_updated_at=(value) ⇒ Object
- .reboot ⇒ Object
- .reload ⇒ Object
- .state ⇒ Object
- .state=(value) ⇒ Object
- .to_json(*args) ⇒ Object
- .version ⇒ Object
Class Method Details
.actual_modified_at ⇒ Object
44 45 46 |
# File 'app/models/terminal.rb', line 44 def self.actual_modified_at self.modified_at.value || DateTime.now end |
.as_json(*args) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/models/terminal.rb', line 103 def self.as_json(*args) { :modified_at => Terminal.actual_modified_at, :logo_url => Terminal.logo_url, :keyword => Terminal.keyword, :support_phone => Terminal.support_phone.value, :groups => Group.all.map{|x| x.as_json}, :providers => Provider.active.map{|x| x.as_json}, :promotions => Promotion.order(:priority).limit(6).map{|x| x.provider_id} } end |
.condition ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'app/models/terminal.rb', line 119 def self.condition { :ip => ip, :state => Terminal.state, :banknotes => Payment.merge_banknotes(Payment.uncollected), :cash => Payment.merge_cash(Payment.uncollected.cash), :cashless => Payment.merge_cash(Payment.uncollected.cashless), :providers => { :updated_at => Terminal.providers_updated_at, :ids => Provider.select(:foreign_id).map{|x| x.foreign_id} || [] }, :queues => { :payments => Sidekiq::Queue.new('payments').size, :pings => Sidekiq::Queue.new('pings').size, :orders => Sidekiq::Queue.new('orders').size, :sync => Sidekiq::Queue.new('sync').size }, :cash_acceptor => { :error => Smartware.cash_acceptor.error, :model => Smartware.cash_acceptor.model, :version => Smartware.cash_acceptor.version }, :printer => { :error => Smartware.printer.error, :model => Smartware.printer.model, :version => Smartware.printer.version }, :modem => { :error => Smartware.modem.error, :signal_level => Smartware.modem.signal_level, :balance => Smartware.modem.balance, :model => Smartware.modem.model, :version => Smartware.modem.version }, :version => Terminal.version } end |
.config ⇒ Object
CONDITON
74 75 76 |
# File 'app/models/terminal.rb', line 74 def self.config @config ||= Smartkiosk::Config::YAML.new(Application.root.join 'config/services/application.yml') end |
.disable ⇒ Object
28 29 30 |
# File 'app/models/terminal.rb', line 28 def self.disable self.state = 'disabled' end |
.enable ⇒ Object
STATES
24 25 26 |
# File 'app/models/terminal.rb', line 24 def self.enable self.state = 'active' end |
.enabled? ⇒ Boolean
82 83 84 |
# File 'app/models/terminal.rb', line 82 def self.enabled? self.state == 'active' end |
.ip ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'app/models/terminal.rb', line 90 def self.ip orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true UDPSocket.open do |s| s.connect '64.233.187.99', 1 s.addr.last end rescue '0.0.0.0' ensure Socket.do_not_reverse_lookup = orig end |
.keyword ⇒ Object
78 79 80 |
# File 'app/models/terminal.rb', line 78 def self.keyword config.keyword end |
.payment_in_progress? ⇒ Boolean
32 33 34 |
# File 'app/models/terminal.rb', line 32 def self.payment_in_progress? self.payment_in_progress.value == "true" end |
.ping ⇒ Object
ACTIONS
59 60 61 |
# File 'app/models/terminal.rb', line 59 def self.ping PingWorker.perform_async end |
.providers_updated_at ⇒ Object
48 49 50 |
# File 'app/models/terminal.rb', line 48 def self.providers_updated_at self.providers_updates[self.config.host] rescue nil end |
.providers_updated_at=(value) ⇒ Object
52 53 54 |
# File 'app/models/terminal.rb', line 52 def self.providers_updated_at=(value) self.providers_updates = {self.config.host => value} end |
.reboot ⇒ Object
67 68 69 |
# File 'app/models/terminal.rb', line 67 def self.reboot Smartguard::Client.reboot_async end |
.reload ⇒ Object
63 64 65 |
# File 'app/models/terminal.rb', line 63 def self.reload Smartguard::Client.restart_async end |
.state ⇒ Object
36 37 38 |
# File 'app/models/terminal.rb', line 36 def self.state self.actual_state.value || 'active' end |
.state=(value) ⇒ Object
40 41 42 |
# File 'app/models/terminal.rb', line 40 def self.state=(value) self.actual_state = value end |
.to_json(*args) ⇒ Object
115 116 117 |
# File 'app/models/terminal.rb', line 115 def self.to_json(*args) as_json.to_json end |
.version ⇒ Object
86 87 88 |
# File 'app/models/terminal.rb', line 86 def self.version '0.1' end |