Class: Cumulus::S3::LoggingConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/s3/models/LoggingConfig.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json = nil) ⇒ LoggingConfig

Public: Constructor

json - a hash representing the JSON configuration. Expects to be handed

the 'logging' node of S3 configuration.


11
12
13
14
15
16
# File 'lib/s3/models/LoggingConfig.rb', line 11

def initialize(json = nil)
  if json
    @target_bucket = json["target-bucket"]
    @prefix = json["prefix"] || ""
  end
end

Instance Attribute Details

#prefixObject (readonly)

Returns the value of attribute prefix.



5
6
7
# File 'lib/s3/models/LoggingConfig.rb', line 5

def prefix
  @prefix
end

#target_bucketObject (readonly)

Returns the value of attribute target_bucket.



4
5
6
# File 'lib/s3/models/LoggingConfig.rb', line 4

def target_bucket
  @target_bucket
end

Instance Method Details

#!=(other) ⇒ Object

Public: Check if this LoggingConfig is not equal to the other object

other - the other object to check

Returns whether this LoggingConfig is not equal to ‘other`



68
69
70
# File 'lib/s3/models/LoggingConfig.rb', line 68

def !=(other)
  !(self == other)
end

#==(other) ⇒ Object

Public: Check LoggingConfig equality with other objects

other - the other object to check

Returns whether this LoggingConfig is equal to ‘other`



53
54
55
56
57
58
59
60
61
# File 'lib/s3/models/LoggingConfig.rb', line 53

def ==(other)
  if !other.is_a? LoggingConfig or
      @target_bucket != other.target_bucket or
      @prefix != other.prefix
    false
  else
    true
  end
end

#populate!(aws) ⇒ Object

Public: Populate this LoggingConfig with the values in an AWS BucketLogging object.

aws - the aws object to populate from



22
23
24
25
# File 'lib/s3/models/LoggingConfig.rb', line 22

def populate!(aws)
  @target_bucket = aws.logging_enabled.target_bucket
  @prefix = aws.logging_enabled.target_prefix
end

#to_awsObject

Public: Produce a hash that is compatible with AWS logging configuration.

Returns the logging configuration in AWS format



30
31
32
33
34
35
# File 'lib/s3/models/LoggingConfig.rb', line 30

def to_aws
  {
    target_bucket: @target_bucket,
    target_prefix: @prefix
  }
end

#to_hObject

Public: Convert this LoggingConfig to a hash that matches Cumulus configuration.

Returns the hash



41
42
43
44
45
46
# File 'lib/s3/models/LoggingConfig.rb', line 41

def to_h
  {
    "target-bucket" => @target_bucket,
    "prefix" => @prefix,
  }.reject { |k, v| v.nil? }
end

#to_sObject



72
73
74
75
76
77
78
# File 'lib/s3/models/LoggingConfig.rb', line 72

def to_s
  if @target_bucket and @prefix
    "Target bucket: #{@target_bucket} with prefix #{@prefix}"
  elsif @target_bucket
    "Target bucket: #{@target_bucket}"
  end
end