Module: Insup
- Defined in:
- lib/insup.rb,
lib/insup/version.rb
Defined Under Namespace
Modules: Exceptions, Insales
Classes: Git, Settings, TrackedFile, Tracker, Uploader
Constant Summary
collapse
- VERSION =
'0.1.2'
Class Method Summary
collapse
Class Method Details
.commit(changed_files = nil) ⇒ Object
49
50
51
52
53
54
55
56
57
|
# File 'lib/insup.rb', line 49
def self.commit(changed_files = nil)
begin
changed_files ||= get_changes
uploader = get_uploader
uploader.process_all changed_files
rescue => ex
puts ex
end
end
|
.init(dir = nil) ⇒ Object
Initializes a directory with a default .insup file
7
8
9
10
11
12
|
# File 'lib/insup.rb', line 7
def self.init(dir = nil)
dir ||= Dir.getwd
template_file = File.join(File.dirname(File.expand_path(__FILE__)), '../.insup.template')
FileUtils.cp(template_file, File.join(dir, '.insup'))
end
|
.list_files(options = {}) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/insup.rb', line 18
def self.list_files(options = {})
files = case options[:mode]
when nil
tracker.tracked_files
when :all
tracker.all_files
when :ignored
tracker.ignored_files
end
puts files
end
|
.list_locations ⇒ Object
14
15
16
|
# File 'lib/insup.rb', line 14
def self.list_locations
puts Insup::Settings.instance.tracked_locations
end
|
.listen ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/insup.rb', line 81
def self.listen
puts 'Listening...'
listener = Listener.new(Dir.getwd)
listener.listen do |changes|
changes.each do |change|
case change.state
when Insup::TrackedFile::DELETED
uploader.remove_file(change)
else
uploader.upload_file(change)
end
end
end
exit_requested = false
Kernel.trap( "INT" ) { exit_requested = true }
while !exit_requested do
sleep 0.1
end
puts 'Stopping listener...'
listener.stop
puts 'Terminated by user'
end
|
.print_config ⇒ Object
72
73
74
75
76
77
78
79
|
# File 'lib/insup.rb', line 72
def self.print_config
puts "Tracker: #{Insup::Settings.instance.tracker['class']}"
puts "Uploader: #{Insup::Settings.instance.uploader['class']}"
puts 'Tracked locations:'
puts Settings.instance.tracked_locations.map{|loc| "\t#{loc}"}
puts 'Ignore patterns:'
puts Settings.instance.ignore_patterns.map{|ip| "\t#{ip}"}
end
|
.status ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/insup.rb', line 59
def self.status
tracker.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
|
.tracker ⇒ Object
40
41
42
43
44
45
46
47
|
# File 'lib/insup.rb', line 40
def self.tracker
@tracker ||= if tracker_conf = Settings.instance.tracker
klass = Insup::Tracker.find_tracker(tracker_conf['class']) || Object::const_get(tracker_conf['class'])
klass.new(tracker_conf)
else
Tracker::SimpleTracker.new({})
end
end
|
.uploader ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'lib/insup.rb', line 31
def self.uploader
@uploader ||= if uploader_conf = Settings.instance.uploader
klass = Insup::Uploader.find_uploader(uploader_conf['class']) || Object::const_get(uploader_conf['class'])
klass.new(uploader_conf)
else
Uploader::Dummy.new({})
end
end
|