Created
July 9, 2013 04:54
-
-
Save jgrevich/5954810 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'celluloid/autostart' | |
module PIFRecord | |
PIFRECORD_ROOT = File.expand_path('.') | |
Dir[File.join(PIFRECORD_ROOT,"lib/pif_record/*.rb")].each {|file| require file } | |
# Handle the input, this would probably run some method | |
# as a part of the DSL you'd have to create. Place this | |
# repl as your command line interface to your service. | |
end | |
def handle_input(input) | |
case | |
when input == "start" || input == 'sa' | |
# result = 'start' | |
result = PIFRecord::Record.new | |
when input == 'stop' || input == 'so' | |
result = PIFRecord::Record.stop | |
when input == 'exit' || input == 'x' | |
eval('exit') | |
else | |
eval(input) | |
end | |
puts(" => #{result}") | |
rescue | |
result = 'What you talking about willis?' | |
puts(" => #{result}") | |
end | |
# This is a lambda that runs the content of the block | |
# after the input is chomped. | |
repl = -> prompt do | |
print prompt | |
handle_input(gets.chomp!) | |
end | |
# After evaling and returning, fire up the prompt lambda | |
# again, this loops after every input and exits with | |
# exit or a HUP. | |
loop do | |
repl[">> "] | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment