lib/ronin/cache/overlay_cache.rb in ronin-0.1.0 vs lib/ronin/cache/overlay_cache.rb in ronin-0.1.1

- old
+ new

@@ -44,18 +44,16 @@ super() @path = File.expand_path(path) if File.file?(@path) - File.open(@path) do |file| - descriptions = YAML.load(file) + descriptions = YAML.load(File.read(@path)) - if descriptions.kind_of?(Array) - descriptions.each do |repo| - if repo.kind_of?(Hash) - add(Overlay.new(repo[:path],repo[:media],repo[:uri])) - end + if descriptions.kind_of?(Array) + descriptions.each do |overlay| + if overlay.kind_of?(Hash) + add(Overlay.new(overlay[:path],overlay[:media],overlay[:uri])) end end end end @@ -133,15 +131,17 @@ # cache.add(repo) do |cache| # puts "Overlay #{repo} added" # end # def add(repo,&block) - if has_overlay?(repo.name) - raise(OverlayCached,"overlay #{repo.to_s.dump} already present in the cache #{self.to_s.dump}",caller) + name = repo.name.to_s + + if has_overlay?(name) + raise(OverlayCached,"overlay #{name.dump} already present in the cache #{self.to_s.dump}",caller) end - self[repo.name.to_s] = repo + self << repo block.call(self) if block return self end @@ -155,15 +155,17 @@ # cache.remove(repo) do |cache| # puts "Overlay #{repo} removed" # end # def remove(repo,&block) - unless has_overlay?(repo.name) - raise(OverlayNotFound,"overlay #{repo.to_s.dump} is not present in the cache #{to_s.dump}",caller) + name = repo.name.to_s + + unless has_overlay?(name) + raise(OverlayNotFound,"overlay #{name.dump} is not present in the cache #{self.to_s.dump}",caller) end - delete_if { |key,value| key==repo.name } + delete_if { |key,value| key == name } block.call(self) if block return self end @@ -198,10 +200,14 @@ block.call(self) if block File.open(output_path,'w') do |output| descriptions = overlays.map do |repo| - {:media_type => repo.media_type, :path => repo.path, :uri => repo.uri} + { + :media_type => repo.media_type, + :path => repo.path, + :uri => repo.uri + } end YAML.dump(descriptions,output) end