Class: Reservoir::Application
- Inherits:
-
Object
- Object
- Reservoir::Application
- Defined in:
- lib/reservoir/application.rb
Instance Attribute Summary collapse
-
#display ⇒ Object
Returns the value of attribute display.
Instance Method Summary collapse
- #exception_message(error) ⇒ Object
- #flush ⇒ Object
-
#initialize(data = {}) ⇒ Application
constructor
A new instance of Application.
- #interactive_message ⇒ Object
- #interactive_quit_message ⇒ Object
- #print(output) ⇒ Object
- #project_message(project) ⇒ Object
- #run(args) ⇒ Object
- #usage_message ⇒ Object
- #user_input ⇒ Object
- #version_message ⇒ Object
- #which_version_message(script, version, path) ⇒ Object
Constructor Details
#initialize(data = {}) ⇒ Application
Returns a new instance of Application.
9 10 11 12 13 |
# File 'lib/reservoir/application.rb', line 9 def initialize(data = {}) @display = data[:display] || :stdio @file_resets = [] @version_displayed_already = false end |
Instance Attribute Details
#display ⇒ Object
Returns the value of attribute display.
7 8 9 |
# File 'lib/reservoir/application.rb', line 7 def display @display end |
Instance Method Details
#exception_message(error) ⇒ Object
29 30 31 |
# File 'lib/reservoir/application.rb', line 29 def (error) print "ERROR: #{error.}\n\n #{error.backtrace.join('\n ')}" end |
#flush ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/reservoir/application.rb', line 104 def flush return if @file_resets.include?(display) return unless is_file? @version_displayed_already = false @file_resets<< display File.delete(@display[:filename]) if File.exist?(@display[:filename]) end |
#interactive_message ⇒ Object
41 42 43 |
# File 'lib/reservoir/application.rb', line 41 def print "Welcome to reservoir interactive shell" end |
#interactive_quit_message ⇒ Object
45 46 47 |
# File 'lib/reservoir/application.rb', line 45 def print "Goodbye" end |
#print(output) ⇒ Object
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/reservoir/application.rb', line 112 def print(output) if @display == :stdio STDOUT.puts output elsif is_file? system("mkdir -p #{Pathname.new(@display[:filename]).parent}") open(@display[:filename], 'a+') { |f| f.puts(output) } else output end end |
#project_message(project) ⇒ Object
33 34 35 |
# File 'lib/reservoir/application.rb', line 33 def (project) print "server: #{project.name}\nfile: #{project.file}\n" end |
#run(args) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/reservoir/application.rb', line 49 def run(args) if args.nil? || args.empty? return end if "-i" == args[0] v = Version.new loop do script = user_input if script == "quit" || script == "exit" return end v.go(script) print v.version end return end if ["--version","-version","-v","--v","version"].include?(args[0]) return end if ["--help","-help","-h","--h","help"].include?(args[0]) return end begin args.each do |filename| all_projects = Project.load_from_file(filename) all_projects.each do |p| self.display = p.display self.flush (p) unless is_data_only? p.scripts.each do |script| which_script = p.template(WhichScript) version = p.template(Version) which_script.go(script) version.go(script) (script,version.version,which_script.response) end end end rescue ($!) end end |
#usage_message ⇒ Object
25 26 27 |
# File 'lib/reservoir/application.rb', line 25 def print "USAGE: reservoir <project_file1> <project_file2> ...\n or reservoir help to see this message\n" end |
#user_input ⇒ Object
123 124 125 |
# File 'lib/reservoir/application.rb', line 123 def user_input STDIN.gets.chomp end |
#version_message ⇒ Object
19 20 21 22 23 |
# File 'lib/reservoir/application.rb', line 19 def return nil if @version_displayed_already @version_displayed_already = true print "reservoir, version #{Reservoir::VERSION}\n" end |
#which_version_message(script, version, path) ⇒ Object
37 38 39 |
# File 'lib/reservoir/application.rb', line 37 def (script,version,path) print "#{script} : #{version} : #{path}\n" end |