Class: CheckCheckIt::Console

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Console

Returns a new instance of Console.



11
12
13
14
# File 'lib/checkcheckit/console.rb', line 11

def initialize(opts = {})
  @out_stream = opts[:out_stream] || $stdout
  @in_stream  = opts[:in_stream]  || $stdin
end

Instance Attribute Details

#in_streamObject

Returns the value of attribute in_stream.



9
10
11
# File 'lib/checkcheckit/console.rb', line 9

def in_stream
  @in_stream
end

#list_dirObject

Returns the value of attribute list_dir.



8
9
10
# File 'lib/checkcheckit/console.rb', line 8

def list_dir
  @list_dir
end

#out_streamObject

Returns the value of attribute out_stream.



9
10
11
# File 'lib/checkcheckit/console.rb', line 9

def out_stream
  @out_stream
end

#web_socketObject

Returns the value of attribute web_socket.



9
10
11
# File 'lib/checkcheckit/console.rb', line 9

def web_socket
  @web_socket
end

Instance Method Details

#debug?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/checkcheckit/console.rb', line 37

def debug?
  @options['d'] || @options['debug']
end

#dirObject



16
17
18
# File 'lib/checkcheckit/console.rb', line 16

def dir
  File.expand_path(@list_dir)
end

#list(args) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/checkcheckit/console.rb', line 83

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



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/checkcheckit/console.rb', line 20

def run!(args = [])
  @options  = Lucy::Goosey.parse_options(args)
  @options['email'] ||= ENV['CHECKCHECKIT_EMAIL']
  @list_dir = File.expand_path(@options.fetch('home', '~/checkcheckit'))

  if args.length == 0
    puts "No command given".red
  else
    method = args.shift
    if respond_to? method
      send method, args
    else
      puts "did not understand: #{method}"
    end
  end
end

#start(args) ⇒ Object



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
81
# File 'lib/checkcheckit/console.rb', line 41

def start(args)
  target = args.first
  unless target
    puts "No list given.\n\n"
    list(args)
    return
  end

  expanded_target = File.expand_path(target)
  list_name = nil

  # see if its a Path
  if File.exists?(expanded_target)
    list_name = expanded_target
  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