Class: RBarman::WalFile

Inherits:
Object
  • Object
show all
Defined in:
lib/rbarman/wal_file.rb

Overview

Represents a wal file

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWalFile

Creates a new instance of RBarman::WalFile



60
61
# File 'lib/rbarman/wal_file.rb', line 60

def initialize
end

Instance Attribute Details

#compressionSymbol? #compression=Object

Overloads:

  • #compressionSymbol?

    Returns compression type of wal file, ‘:none`, `:gzip`, `:bzip2`, `:custom`.

    Returns:

    • (Symbol, nil)

      compression type of wal file, ‘:none`, `:gzip`, `:bzip2`, `:custom`

  • #compression=Object

    Compression type of wal file

    Parameters:

    • compression (Symbol)

      compression type

    Raises:

    • (ArgumentError)

      if compression is not one of ‘:none`, `:gzip`, `:bzip2`, `:custom`



49
50
51
# File 'lib/rbarman/wal_file.rb', line 49

def compression
  @compression
end

#createdTime? #created=Object

Overloads:

  • #createdTime?

    Returns time when wal file has been created.

    Returns:

    • (Time, nil)

      time when wal file has been created

  • #created=Object

    Time when wal file has been created

    Parameters:

    • created (Time, Numeric, String)

      the time



41
42
43
# File 'lib/rbarman/wal_file.rb', line 41

def created
  @created
end

#segmentString? #segment=Object

Overloads:

  • #segmentString?

    Returns segment part of the wal file.

    Returns:

    • (String, nil)

      segment part of the wal file

  • #segment=Object

    segment part of the wal file

    Parameters:

    • segment (#to_s)

      the segment part

    Raises:

    • (ArgumentError)

      if segment length != 8



34
35
36
# File 'lib/rbarman/wal_file.rb', line 34

def segment
  @segment
end

#sizeInteger? #size=Object

Overloads:

  • #sizeInteger?

    Returns size of wal file (in bytes).

    Returns:

    • (Integer, nil)

      size of wal file (in bytes)

  • #size=Object

    Size of wal file (in bytes)

    Parameters:

    • size (#to_i)

      size of wal file (in bytes)



57
58
59
# File 'lib/rbarman/wal_file.rb', line 57

def size
  @size
end

#timelineString? #timeline=Object

Overloads:

  • #timelineString?

    Returns timeline part of the wal file.

    Returns:

    • (String, nil)

      timeline part of the wal file

  • #timeline=Object

    Timeline part of the wal file

    Parameters:

    • timeline (#to_s)

      the timeline part

    Raises:

    • (ArgumentError)

      if timeline length != 8



18
19
20
# File 'lib/rbarman/wal_file.rb', line 18

def timeline
  @timeline
end

#xlogString? #xlog=Object

Overloads:

  • #xlogString?

    Returns xlog part of the wal file.

    Returns:

    • (String, nil)

      xlog part of the wal file

  • #xlog=Object

    xlog part of the wal file

    Parameters:

    • xlog (#to_s)

      the xlog part

    Raises:

    • (ArgumentError)

      if xlog length != 8



26
27
28
# File 'lib/rbarman/wal_file.rb', line 26

def xlog
  @xlog
end

Class Method Details

.parse(name) ⇒ WalFile

Creates a new WalFile from the given argument

Parameters:

Returns:

  • (WalFile)

    the created WalFile

Raises:

  • (InvalidWalFileNameError)

    if name is a string and string’s length isn’t exactly 24 chars or name could not be splitted in 3 parts (timeline|xlog|segment)



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/rbarman/wal_file.rb', line 108

def self.parse(name)
  raise(InvalidWalFileNameError, "name has to be exactly 24 chars") if !name.is_a? WalFile and name.to_s.size != 24 

  if name.is_a? WalFile
    wal_file = name
  else
    splitted = name.to_s.scan(/.{8}/)
    raise InvalidWalFileNameError if splitted.count != 3

    wal_file = WalFile.new
    wal_file.timeline = splitted[0]
    wal_file.xlog = splitted[1]
    wal_file.segment = splitted[2]
  end

  return wal_file
end

Instance Method Details

#==(other) ⇒ Boolean

Checks if other is equal to self by comparing timeline, xlog and segment

Parameters:

Returns:

  • (Boolean)

    if other is equal to self



129
130
131
132
133
# File 'lib/rbarman/wal_file.rb', line 129

def ==(other)
  o = other
  o = WalFile.parse(other.to_s) if !other.is_a? WalFile
  return o.timeline == @timeline && o.xlog == @xlog && o.segment == @segment
end

#to_sObject



63
64
65
# File 'lib/rbarman/wal_file.rb', line 63

def to_s
  "#{timeline}#{xlog}#{segment}"
end