Module: Insup::Console
- Defined in:
- lib/insup/console.rb
Defined Under Namespace
Classes: UploadObserver
Class Method Summary collapse
- .commit(args) ⇒ Object
- .init(directory = nil) ⇒ Object
- .init_log(settings) ⇒ Object
- .insales_list_themes ⇒ Object
- .list_files(options = {}) ⇒ Object
- .list_locations ⇒ Object
- .listen ⇒ Object
- .print_config ⇒ Object
- .process_error(exception) ⇒ Object
- .start(settings_file = nil, verbose = false, debug = false) ⇒ Object
- .status ⇒ Object
Class Method Details
.commit(args) ⇒ Object
112 113 114 115 |
# File 'lib/insup/console.rb', line 112 def self.commit(args) @insup.uploader.add_observer(Insup::Console::UploadObserver.new) @insup.commit(args) end |
.init(directory = nil) ⇒ Object
49 50 51 52 |
# File 'lib/insup/console.rb', line 49 def self.init(directory = nil) directory ||= Dir.getwd Insup.create_insup_file(directory) end |
.init_log(settings) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/insup/console.rb', line 17 def self.init_log(settings) if settings.log_file.nil? || settings.log_file.empty? @logger = Logger.new($stdout) else log_dir = File.dirname(settings.log_file) FileUtils.mkdir_p(log_dir) if !Dir.exist?(log_dir) @logger = Logger.new(settings.log_file) end @logger.level = @debug ? Logger::DEBUG : settings.log_level @logger.formatter = proc do |severity, datetime, progname, msg| format_string = settings.log_pattern values_hash = { level: severity, timestamp: datetime } if msg.is_a? Exception values_hash[:message] = msg. values_hash[:backtrace] = "\n#{msg.backtrace.join("\n")}" else values_hash[:message] = msg.to_s values_hash[:backtrace] = nil end format_string % values_hash end Insup.logger = @logger end |
.insales_list_themes ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/insup/console.rb', line 66 def self.insales_list_themes theme_id = @settings.uploader['theme_id'] @insup.insales.themes.each do |theme| prefix = theme.id == theme_id ? '=>' : ' ' puts "#{prefix} #{theme.id}\t#{theme.title}" end end |
.list_files(options = {}) ⇒ Object
60 61 62 63 64 |
# File 'lib/insup/console.rb', line 60 def self.list_files( = {}) @insup.files().each do |f| puts f end end |
.list_locations ⇒ Object
54 55 56 57 58 |
# File 'lib/insup/console.rb', line 54 def self.list_locations @insup.tracked_locations.each do |loc| puts loc end end |
.listen ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/insup/console.rb', line 96 def self.listen @insup.uploader.add_observer(Insup::Console::UploadObserver.new) puts 'Listening...' @insup.listen exit_requested = false Kernel.trap( "INT" ) { exit_requested = true } while !exit_requested do sleep 0.1 end puts 'Stopping listener...' @insup.stop_listening puts 'Terminated by user' end |
.print_config ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/insup/console.rb', line 87 def self.print_config puts "Tracker: #{@settings.tracker['class']}" puts "Uploader: #{@settings.uploader['class']}" puts 'Tracked locations:' puts @settings.tracked_locations.map{|loc| "\t#{loc}"} puts 'Ignore patterns:' puts @settings.ignore_patterns.map{|ip| "\t#{ip}"} end |
.process_error(exception) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/insup/console.rb', line 117 def self.process_error(exception) if exception.is_a? Insup::Exceptions::UploaderError $stderr.puts "UploaderError: #{exception.}".red else $stderr.puts "Error: #{exception.}".red end if @debug $stderr.puts exception.backtrace end begin @logger.error(exception) if @logger rescue $stderr.puts "Unable to log error because the logger is not properly configured" end end |
.start(settings_file = nil, verbose = false, debug = false) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/insup/console.rb', line 7 def self.start(settings_file = nil, verbose = false, debug = false) settings_file ||= '.insup' @settings = Insup::Settings.new(settings_file) @insup = Insup.new(Dir.getwd, @settings) @verbose = verbose @debug = debug self.init_log(@settings) true end |
.status ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/insup/console.rb', line 74 def self.status @insup.changes.each do |x| case x.state when Insup::TrackedFile::NEW puts "New: #{x.path}".green when Insup::TrackedFile::MODIFIED puts "Modified: #{x.path}".yellow when Insup::TrackedFile::DELETED puts "Deleted: #{x.path}".red end end end |