Class: Rfid::CLI
Class Method Summary collapse
Instance Method Summary collapse
- #app(method_name = 'start') ⇒ Object
- #checkout(device, *cards) ⇒ Object
- #setup ⇒ Object
- #version ⇒ Object
- #websocket(method_name = 'start') ⇒ Object
Class Method Details
.source_root ⇒ Object
74 75 76 |
# File 'lib/rfid/cli.rb', line 74 def self.source_root File.dirname(File.('../../', __FILE__)) end |
Instance Method Details
#app(method_name = 'start') ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/rfid/cli.rb', line 17 def app(method_name = 'start') path = self.class.source_root config = File.join(path, 'config/thin.yml') rack = File.join(path, 'config.ru') in_root do run "thin #{method_name} -R #{rack} -C #{config} --chdir #{path}", :verbose => false end end |
#checkout(device, *cards) ⇒ Object
29 30 31 32 33 |
# File 'lib/rfid/cli.rb', line 29 def checkout(device, *cards) event = Rfid::Event.new(device, cards) say "Create new event on device #{event.device_id} (#{device})", :green event.save end |
#setup ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rfid/cli.rb', line 38 def setup require 'yaml/store' if [:force] say("Reset settings to defaults", :red) copy_file("config/rfid.yml.sample", File.join(self.class.source_root, "config/rfid.yml")) end say("Press ENTER if you don't want change current value", :green) store = YAML::Store.new(Rfid.config_path) store.transaction do Rfid.config.table.each do |key, value| value = ask("#{key} (#{value}):", :yellow) unless value.blank? store[key.to_s] = value say_status :set, "#{key} => #{value}" end end end say("Setup init script", :green) copy_file "lib/templates/init", "/etc/init.d/rfid" chmod "/etc/init.d/rfid", 0755 say("Setup completed", :green) end |
#version ⇒ Object
69 70 71 |
# File 'lib/rfid/cli.rb', line 69 def version say "Rfid version #{Rfid::VERSION}" end |
#websocket(method_name = 'start') ⇒ Object
10 11 12 13 |
# File 'lib/rfid/cli.rb', line 10 def websocket(method_name = 'start') command = File.join(self.class.source_root, 'lib/runner.rb') run_ruby_script "#{command} #{method_name}", :verbose => false end |