Class: Bitferry::Endpoint::Bitferry

Inherits:
Bitferry::Endpoint show all
Defined in:
lib/bitferry.rb

Constant Summary

Constants inherited from Bitferry::Endpoint

ROUTE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Bitferry::Endpoint

restore

Constructor Details

#initialize(volume, path) ⇒ Bitferry

Returns a new instance of Bitferry.

Raises:

  • (ArgumentError)


1449
1450
1451
1452
1453
# File 'lib/bitferry.rb', line 1449

def initialize(volume, path)
  @volume_tag = volume.tag
  @path = Pathname.new(path)
  raise ArgumentError, "expected relative path but got #{self.path}" if (Volume::ENCOMPASSING_PATH_PREFIX =~ self.path.to_s).nil?
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



1443
1444
1445
# File 'lib/bitferry.rb', line 1443

def path
  @path
end

#volume_tagObject (readonly)

Returns the value of attribute volume_tag.



1440
1441
1442
# File 'lib/bitferry.rb', line 1440

def volume_tag
  @volume_tag
end

Instance Method Details

#externalizeObject



1462
1463
1464
1465
1466
1467
1468
# File 'lib/bitferry.rb', line 1462

def externalize
  {
    endpoint: :bitferry,
    volume: volume_tag,
    path: path.to_s.empty? ? nil : path
  }.compact
end

#generationObject



1480
1481
1482
1483
# File 'lib/bitferry.rb', line 1480

def generation
  v = Volume[volume_tag]
  v ? v.generation : 0
end

#intact?Boolean

Returns:

  • (Boolean)


1474
# File 'lib/bitferry.rb', line 1474

def intact? = !Volume[volume_tag].nil?

#refers?(volume) ⇒ Boolean

Returns:

  • (Boolean)


1477
# File 'lib/bitferry.rb', line 1477

def refers?(volume) = volume.tag == volume_tag

#restore(hash) ⇒ Object



1456
1457
1458
1459
# File 'lib/bitferry.rb', line 1456

def restore(hash)
  @volume_tag = hash.fetch(:volume)
  @path = Pathname.new(hash.fetch(:path, ''))
end

#rootObject



1446
# File 'lib/bitferry.rb', line 1446

def root = Volume[volume_tag].root.join(path)

#show_statusObject



1471
# File 'lib/bitferry.rb', line 1471

def show_status = intact? ? ":#{volume_tag}:#{path}" : ":{#{volume_tag}}:#{path}"