Class: Insup
- Inherits:
-
Object
show all
- Defined in:
- lib/insup.rb,
lib/insup/version.rb
Defined Under Namespace
Modules: Console, Exceptions
Classes: Git, Insales, Settings, TrackedFile, Tracker, Uploader
Constant Summary
collapse
- VERSION =
'0.4'
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(base, settings) ⇒ Insup
Returns a new instance of Insup.
14
15
16
17
|
# File 'lib/insup.rb', line 14
def initialize(base, settings)
@settings = settings
@base = base
end
|
Class Method Details
.create_insup_file(dir = nil) ⇒ Object
Initializes a directory with a default .insup file
20
21
22
23
24
25
|
# File 'lib/insup.rb', line 20
def self.create_insup_file(dir = nil)
dir ||= Dir.getwd
template_file = File.join(File.dirname(File.expand_path(__FILE__)), '../insup.template')
path = File.join(dir, '.insup')
FileUtils.cp(template_file, path) if !File.exist?(path)
end
|
.logger ⇒ Object
10
11
12
|
# File 'lib/insup.rb', line 10
def self.logger
@logger
end
|
.logger=(val) ⇒ Object
5
6
7
8
|
# File 'lib/insup.rb', line 5
def self.logger=(val)
@logger = val
Insup::Insales.logger = @logger
end
|
Instance Method Details
#changes ⇒ Object
79
80
81
|
# File 'lib/insup.rb', line 79
def changes
tracker.changes
end
|
#commit(files = nil) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/insup.rb', line 42
def commit(files = nil)
if files.nil? || files.empty?
list = changes
else
list = files.map do |f|
mode = File.exist?(f) ? TrackedFile::MODIFIED : TrackedFile::DELETED
TrackedFile.new(f, mode)
end
end
list.each do |file|
uploader.process_file(file)
end
end
|
#files(options = {}) ⇒ Object
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/insup.rb', line 31
def files(options = {})
files = case options[:mode]
when nil
tracker.tracked_files
when :all
tracker.all_files
when :ignored
tracker.ignored_files
end
end
|
#insales ⇒ Object
75
76
77
|
# File 'lib/insup.rb', line 75
def insales
@insales ||= Insales.new(@settings)
end
|
#listen ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/insup.rb', line 83
def listen
@listener = Listener.new(@base, @settings)
@listener.listen do |changes|
begin
changes.each do |change|
uploader.process_file(change)
end
rescue Exceptions::RecoverableUploaderError => ex
logger.error(ex)
end
end
end
|
#stop_listening ⇒ Object
96
97
98
|
# File 'lib/insup.rb', line 96
def stop_listening
@listener.stop
end
|
#tracked_locations ⇒ Object
27
28
29
|
# File 'lib/insup.rb', line 27
def tracked_locations
@settings.tracked_locations
end
|
#tracker ⇒ Object
66
67
68
69
70
71
72
73
|
# File 'lib/insup.rb', line 66
def tracker
@tracker ||= if tracker_conf = @settings.tracker
klass = Insup::Tracker.find_tracker(tracker_conf['class']) || Object::const_get(tracker_conf['class'])
klass.new(@base, @settings)
else
Tracker::SimpleTracker.new(@settings)
end
end
|
#uploader ⇒ Object
57
58
59
60
61
62
63
64
|
# File 'lib/insup.rb', line 57
def uploader
@uploader ||= if uploader_conf = @settings.uploader
klass = Insup::Uploader.find_uploader(uploader_conf['class']) || Object::const_get(uploader_conf['class'])
klass.new(@settings)
else
Uploader::DummyUploader.new(@settings)
end
end
|