Class: Dobby::Database
- Inherits:
-
Object
- Object
- Dobby::Database
- Includes:
- Enumerable
- Defined in:
- lib/dobby/database.rb
Overview
A set of Defects that knows how to update itself.
Defined Under Namespace
Classes: InitializationError
Instance Method Summary collapse
- #[](key) ⇒ Array<Dobby::Defect>?
-
#contains?(key) ⇒ Boolean
True if at least one Defect exists for key.
- #defects_for(package) ⇒ Array<Dobby::Defect>
- #each {|Iterator| ... } ⇒ Object
-
#initialize(strategy) ⇒ Database
constructor
A new instance of Database.
-
#update ⇒ true
If strategy reports it has new content.
Constructor Details
#initialize(strategy) ⇒ Database
Returns a new instance of Database.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/dobby/database.rb', line 10 def initialize(strategy) @records = Hash.new { |h, k| h[k] = [] } @strategy = strategy raise InitializationError, 'Strategy did not update at initialize!' unless update # TODO: Make the flag path configurable file = File.join(File.(__dir__), 'flags.yml') flags = Psych.load_file(file) flags.each do |flag, defects| defects.each { |d| @records[d].flag = flag if @records.key?(d) } end end |
Instance Method Details
#[](key) ⇒ Array<Dobby::Defect>?
34 35 36 |
# File 'lib/dobby/database.rb', line 34 def [](key) @records[key] end |
#contains?(key) ⇒ Boolean
Returns true if at least one Dobby::Defect exists for key.
41 42 43 |
# File 'lib/dobby/database.rb', line 41 def contains?(key) @records.key? key end |
#defects_for(package) ⇒ Array<Dobby::Defect>
26 27 28 |
# File 'lib/dobby/database.rb', line 26 def defects_for(package) @records[package.name] | @records[package.source] end |
#each {|Iterator| ... } ⇒ Object
Iterate over all Packages in the database and their associated Dobby::Defects
48 49 50 |
# File 'lib/dobby/database.rb', line 48 def each(&block) @records.each(&block) end |
#update ⇒ true
Returns if strategy reports it has new content.
53 54 55 56 57 58 59 60 |
# File 'lib/dobby/database.rb', line 53 def update response = @strategy.update return false unless response.changed? @records.clear @records.merge!(response.content) true end |