Permalink
Browse files

Add Archive.by_merging(hars)

  • Loading branch information...
1 parent c22c2f0 commit aa2359a322db206d665bffcd64bf06c11ff27f70 @jarib committed Jan 10, 2011
Showing with 29 additions and 10 deletions.
  1. +13 −0 lib/har/archive.rb
  2. +11 −10 lib/har/viewer.rb
  3. +5 −0 spec/har/archive_spec.rb
View
@@ -10,6 +10,19 @@ def self.from_file(path)
from_string File.read(path), path
end
+ def self.by_merging(hars)
+ hars = hars.dup
+
+ result = hars.shift
+ result = from_file(result) unless result.kind_of? self
+
+ hars.each do |har|
+ result.merge! har.kind_of?(self) ? har : from_file(har)
+ end
+
+ result
+ end
+
attr_reader :uri
def initialize(input, uri = nil)
View
@@ -10,7 +10,11 @@ def initialize(args)
@running = false
@options = parse(args)
- @har = merge archives_from(args)
+ if @options[:validate]
+ args = validate(args)
+ end
+
+ @har = Archive.by_merging(args)
end
def show
@@ -21,16 +25,13 @@ def show
private
- def archives_from(hars)
- hars = hars.map { |path| Archive.from_file(path) }
-
- if @options[:validate]
- progress("Validating archives...") do
- hars.each { |h| h.validate! }
- end
- end
+ def validate(hars)
+ progress("Validating archives...") {
+ hars = hars.map { |path| Archive.from_file(path) }
+ hars.each { |h| h.validate! }
- hars
+ hars
+ }
end
def create_root
View
@@ -17,6 +17,11 @@ module HAR
ar.uri.should_not be_nil
ar.uri.should include("browser-blocking-time")
end
+
+ it "creates a single archive by merging the given paths" do
+ ar = Archive.by_merging good_hars.first(2)
+ ar.pages.size.should == 3
+ end
end
context "fetching data" do

0 comments on commit aa2359a

Please sign in to comment.