Class: SmallCage::Commands::Auto

Inherits:
Base
  • Object
show all
Defined in:
lib/smallcage/commands/auto.rb

Overview

‘smc auto’ command

Instance Method Summary collapse

Methods inherited from Base

execute, #quiet?

Constructor Details

#initialize(opts) ⇒ Auto

Returns a new instance of Auto.



6
7
8
9
10
11
12
# File 'lib/smallcage/commands/auto.rb', line 6

def initialize(opts)
  super(opts)
  @target = Pathname.new(opts[:path])
  @port = opts[:port]
  @sleep = 1
  @timestamps = {}
end

Instance Method Details

#executeObject



29
30
31
32
33
34
35
36
37
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/smallcage/commands/auto.rb', line 29

def execute
  require 'smallcage/http_server'

  puts_banner

  start_http_server unless @port.nil?
  init_sig_handler

  @loader = SmallCage::Loader.new(@target)

  first_loop = true
  @update_loop = true
  while @update_loop
    if first_loop
      first_loop = false
      if @opts[:fast]
        puts 'Searching modified files since last update...'
        load_initial_timestamps
        count, total = update_modified_files

        if total == 0
          notify
          puts 'All files are updated. Redy to edit!'
        elsif total != count
          notify
          notify
          puts "Error (#{count}/#{total}) Redy to edit!"
        else
          notify
          puts "Updated (#{count}/#{total}) Redy to edit!"
        end
        puts_line
      else
        update_target
        notify
        puts_line
      end
    else
      count, total = update_modified_files
      if total > 0
        if total == count
          notify
        else
          notify
          notify
          puts "Error (#{count} / #{total})"
        end
        puts_line
      end
    end
    sleep @sleep
  end
end