Class: Paradeiser::Repository
- Inherits:
-
Object
- Object
- Paradeiser::Repository
- Defined in:
- lib/paradeiser/models/repository.rb
Class Method Summary collapse
- .active ⇒ Object
- .active? ⇒ Boolean
- .all ⇒ Object
- .all_breaks ⇒ Object
- .all_pomodori ⇒ Object
- .any?(&blk) ⇒ Boolean
- .find(&blk) ⇒ Object
- .last_canceled ⇒ Object
- .last_finished ⇒ Object
- .next_id ⇒ Object
- .save(pom) ⇒ Object
Class Method Details
.active ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/paradeiser/models/repository.rb', line 26 def active all_active = find{|pom| pom.active?}.sort{|a,b| a.started_at <=> b.started_at} # Cannot recover from an internal inconsistency. if all_active.size > 1 raise "The repository was corrupted. There are #{all_active.size} active objects, but only one is allowed to be active." end all_active.last end |
.active? ⇒ Boolean
37 38 39 |
# File 'lib/paradeiser/models/repository.rb', line 37 def active? !!active end |
.all ⇒ Object
4 5 6 7 8 |
# File 'lib/paradeiser/models/repository.rb', line 4 def all backend.transaction(true) do backend.roots.map{|id| backend[id]} end end |
.all_breaks ⇒ Object
14 15 16 |
# File 'lib/paradeiser/models/repository.rb', line 14 def all_breaks all.select{|b| b.kind_of?(Break)} end |
.all_pomodori ⇒ Object
10 11 12 |
# File 'lib/paradeiser/models/repository.rb', line 10 def all_pomodori all.select{|p| p.kind_of?(Pomodoro)} end |
.any?(&blk) ⇒ Boolean
18 19 20 |
# File 'lib/paradeiser/models/repository.rb', line 18 def any?(&blk) all.any?(&blk) end |
.find(&blk) ⇒ Object
22 23 24 |
# File 'lib/paradeiser/models/repository.rb', line 22 def find(&blk) all.select(&blk) end |
.last_canceled ⇒ Object
45 46 47 |
# File 'lib/paradeiser/models/repository.rb', line 45 def last_canceled find{|p| p.canceled?}.sort{|a,b| a.started_at <=> b.started_at}.last end |
.last_finished ⇒ Object
41 42 43 |
# File 'lib/paradeiser/models/repository.rb', line 41 def last_finished find{|p| p.finished?}.sort{|a,b| a.started_at <=> b.started_at}.last end |
.next_id ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/paradeiser/models/repository.rb', line 61 def next_id if all.empty? 1 else all.max{|a, b| a.id <=> b.id}.id.next end end |
.save(pom) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/paradeiser/models/repository.rb', line 49 def save(pom) raise IllegalStatusError if pom.idle? # Do not allow saving of a new active pomodoro while another pomodoro or break is active raise SingletonError.new(pom.class, self.active, :save) if self.active? && pom.new? pom.id = next_id if pom.new? backend.transaction do backend[pom.id] = pom end end |