Class: S3::ListBucketParser

Inherits:
Object
  • Object
show all
Defined in:
lib/s3sync/S3.rb

Overview

Parses the list bucket output into a list of ListEntry objects, and a list of CommonPrefixEntry objects if applicable.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeListBucketParser

Returns a new instance of ListBucketParser.



522
523
524
# File 'lib/s3sync/S3.rb', line 522

def initialize
  reset
end

Instance Attribute Details

#common_prefixesObject (readonly)

Returns the value of attribute common_prefixes.



520
521
522
# File 'lib/s3sync/S3.rb', line 520

def common_prefixes
  @common_prefixes
end

#entriesObject (readonly)

Returns the value of attribute entries.



519
520
521
# File 'lib/s3sync/S3.rb', line 519

def entries
  @entries
end

#propertiesObject (readonly)

Returns the value of attribute properties.



518
519
520
# File 'lib/s3sync/S3.rb', line 518

def properties
  @properties
end

Instance Method Details

#resetObject

get ready for another parse



590
591
592
593
594
595
596
597
# File 'lib/s3sync/S3.rb', line 590

def reset
  @is_echoed_prefix = true;
  @entries = []
  @curr_entry = nil
  @common_prefixes = []
  @common_prefix_entry = nil
  @curr_text = ''
end

#tag_end(name) ⇒ Object

we have one, add him to the entries list



539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
# File 'lib/s3sync/S3.rb', line 539

def tag_end(name)
  # this prefix is the one we echo back from the request
  if name == 'Name'
    @properties.name = @curr_text
  elsif name == 'Prefix' and @is_echoed_prefix
    @properties.prefix = @curr_text       
    @is_echoed_prefix = nil
  elsif name == 'Marker'
    @properties.marker = @curr_text
  elsif name == 'MaxKeys'
    @properties.max_keys = @curr_text.to_i
  elsif name == 'Delimiter'
    @properties.delimiter = @curr_text
  elsif name == 'IsTruncated'
    @properties.is_truncated = @curr_text == 'true'
  elsif name == 'NextMarker'        
    @properties.next_marker = @curr_text
  elsif name == 'Contents'
    @entries << @curr_entry
  elsif name == 'Key'
    @curr_entry.key = @curr_text
  elsif name == 'LastModified'
    @curr_entry.last_modified = @curr_text
  elsif name == 'ETag'
    @curr_entry.etag = @curr_text
  elsif name == 'Size'
    @curr_entry.size = @curr_text.to_i
  elsif name == 'StorageClass'
    @curr_entry.storage_class = @curr_text
  elsif name == 'ID'
    @curr_entry.owner.id = @curr_text
  elsif name == 'DisplayName'
    @curr_entry.owner.display_name = @curr_text
  elsif name == 'CommonPrefixes'
    @common_prefixes << @common_prefix_entry         
  elsif name == 'Prefix'
    # this is the common prefix for keys that match up to the delimiter
    @common_prefix_entry.prefix = @curr_text
  end
  @curr_text = ''
end

#tag_start(name, attributes) ⇒ Object



526
527
528
529
530
531
532
533
534
535
536
# File 'lib/s3sync/S3.rb', line 526

def tag_start(name, attributes)
  if name == 'ListBucketResult'
    @properties = ListProperties.new
  elsif name == 'Contents'
    @curr_entry = ListEntry.new
  elsif name == 'Owner'
    @curr_entry.owner = Owner.new
  elsif name == 'CommonPrefixes'
    @common_prefix_entry = CommonPrefixEntry.new
  end
end

#text(text) ⇒ Object



581
582
583
# File 'lib/s3sync/S3.rb', line 581

def text(text)
    @curr_text += text
end

#xmldecl(version, encoding, standalone) ⇒ Object



585
586
587
# File 'lib/s3sync/S3.rb', line 585

def xmldecl(version, encoding, standalone)
  # ignore
end