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.



527
528
529
# File 'lib/s3sync/S3.rb', line 527

def initialize
  reset
end

Instance Attribute Details

#common_prefixesObject (readonly)

Returns the value of attribute common_prefixes.



525
526
527
# File 'lib/s3sync/S3.rb', line 525

def common_prefixes
  @common_prefixes
end

#entriesObject (readonly)

Returns the value of attribute entries.



524
525
526
# File 'lib/s3sync/S3.rb', line 524

def entries
  @entries
end

#propertiesObject (readonly)

Returns the value of attribute properties.



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

def properties
  @properties
end

Instance Method Details

#resetObject

get ready for another parse



595
596
597
598
599
600
601
602
# File 'lib/s3sync/S3.rb', line 595

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



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
580
581
582
583
584
# File 'lib/s3sync/S3.rb', line 544

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



531
532
533
534
535
536
537
538
539
540
541
# File 'lib/s3sync/S3.rb', line 531

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



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

def text(text)
  @curr_text += text
end

#xmldecl(version, encoding, standalone) ⇒ Object



590
591
592
# File 'lib/s3sync/S3.rb', line 590

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