Class: CheckCheckIt::Console
- Inherits:
-
Object
- Object
- CheckCheckIt::Console
- Defined in:
- lib/checkcheckit/console.rb
Overview
Uses the “big bowl of pudding’ architecture
Constant Summary collapse
- DEFAULT_URL =
'http://checkcheckit.herokuapp.com/'
Instance Attribute Summary collapse
-
#in_stream ⇒ Object
Returns the value of attribute in_stream.
-
#list_dir ⇒ Object
Returns the value of attribute list_dir.
-
#out_stream ⇒ Object
Returns the value of attribute out_stream.
-
#web_socket ⇒ Object
Returns the value of attribute web_socket.
Instance Method Summary collapse
- #debug? ⇒ Boolean
- #dir ⇒ Object
-
#initialize(opts = {}) ⇒ Console
constructor
A new instance of Console.
- #list(args) ⇒ Object
- #run!(args = []) ⇒ Object
- #start(args) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Console
Returns a new instance of Console.
10 11 12 13 |
# File 'lib/checkcheckit/console.rb', line 10 def initialize(opts = {}) @out_stream = opts[:out_stream] || $stdout @in_stream = opts[:in_stream] || $stdin end |
Instance Attribute Details
#in_stream ⇒ Object
Returns the value of attribute in_stream.
8 9 10 |
# File 'lib/checkcheckit/console.rb', line 8 def in_stream @in_stream end |
#list_dir ⇒ Object
Returns the value of attribute list_dir.
7 8 9 |
# File 'lib/checkcheckit/console.rb', line 7 def list_dir @list_dir end |
#out_stream ⇒ Object
Returns the value of attribute out_stream.
8 9 10 |
# File 'lib/checkcheckit/console.rb', line 8 def out_stream @out_stream end |
#web_socket ⇒ Object
Returns the value of attribute web_socket.
8 9 10 |
# File 'lib/checkcheckit/console.rb', line 8 def web_socket @web_socket end |
Instance Method Details
#debug? ⇒ Boolean
36 37 38 |
# File 'lib/checkcheckit/console.rb', line 36 def debug? @options['d'] || @options['debug'] end |
#dir ⇒ Object
15 16 17 |
# File 'lib/checkcheckit/console.rb', line 15 def dir File.(@list_dir) end |
#list(args) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/checkcheckit/console.rb', line 82 def list(args) puts "# Checklists\n" Dir[dir + '/*'].each do |dir| top_level_dir = File.basename dir puts top_level_dir Dir[dir + '/*'].each do |file| list = List.new(file) puts " #{list.name}\t #{list.header}" end end end |
#run!(args = []) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/checkcheckit/console.rb', line 19 def run!(args = []) @options = Lucy::Goosey.(args) @options['email'] ||= ENV['CHECKCHECKIT_EMAIL'] @list_dir = File.(@options.fetch('home', '~/checkcheckit')) if args.length == 0 puts "No command given" else method = args.shift if respond_to? method send method, args else puts "did not understand: #{method}" end end end |
#start(args) ⇒ Object
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/checkcheckit/console.rb', line 40 def start(args) target = args.first unless target puts "No list given.\n\n" list(args) return end = File.(target) list_name = nil # see if its a Path if File.exists?() list_name = else #finding the list list_name = Dir[dir + '/*/*'].find{ |fname| fname.include? target } end if list_name list = List.new(list_name) if (emails = @options['email']) || @options['live'] @list_id = list_id = notify_server_of_start(emails, list) $stderr.puts web_service_url, list_id if debug? url = URI.join(web_service_url, list_id) puts "Live at URL: #{url}" if @options['open'] || @options['O'] Process.detach fork{ exec("open #{url}") } end return if @options['no-cli'] || @options['web-only'] @live = true end step_through_list(list) else puts "Could not find checklist via: #{target}" end end |