Class: AutoCommit::Gatherer
- Inherits:
-
Object
- Object
- AutoCommit::Gatherer
- Defined in:
- lib/autocommit/gatherer.rb
Constant Summary collapse
- Delay =
seconds
0.25
Instance Method Summary collapse
- #commit ⇒ Object
- #delayed_commit ⇒ Object
-
#initialize(dir, committer) ⇒ Gatherer
constructor
A new instance of Gatherer.
- #start_thread ⇒ Object
- #trigger_commit(full_name) ⇒ Object
Constructor Details
#initialize(dir, committer) ⇒ Gatherer
Returns a new instance of Gatherer.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/autocommit/gatherer.rb', line 10 def initialize dir, committer @dir = dir @committer = committer @mutex = Mutex.new @list = [] Detector.new dir do |event| name = event.absolute_name puts "#{name} (#{event.flags})" unless /\.git/ =~ name trigger_commit event.absolute_name end end |
Instance Method Details
#commit ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/autocommit/gatherer.rb', line 42 def commit @mutex.synchronize { @list.clear # Prevent the next commit (>=0.25 seconds later, but still) # from interfering with this one: # commit from within the synchronized block @committer.commit } end |
#delayed_commit ⇒ Object
37 38 39 40 |
# File 'lib/autocommit/gatherer.rb', line 37 def delayed_commit sleep Delay commit end |
#start_thread ⇒ Object
31 32 33 34 35 |
# File 'lib/autocommit/gatherer.rb', line 31 def start_thread Thread.new { delayed_commit } end |
#trigger_commit(full_name) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/autocommit/gatherer.rb', line 22 def trigger_commit full_name in_git_repo = full_name.start_with? File.join(@dir, ".git") return if in_git_repo @mutex.synchronize { start_thread if @list.empty? @list << Time.now } end |