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)


1371
1372
1373
1374
1375
# File 'lib/bitferry.rb', line 1371

def initialize(volume, path)
  @volume_tag = volume.tag
  @path = Pathname.new(path)
  raise ArgumentError, "expected relative path but got #{self.path}" unless (/^[\.\/]/ =~ self.path.to_s).nil?
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



1365
1366
1367
# File 'lib/bitferry.rb', line 1365

def path
  @path
end

#volume_tagObject (readonly)

Returns the value of attribute volume_tag.



1362
1363
1364
# File 'lib/bitferry.rb', line 1362

def volume_tag
  @volume_tag
end

Instance Method Details

#externalizeObject



1384
1385
1386
1387
1388
1389
1390
# File 'lib/bitferry.rb', line 1384

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

#generationObject



1402
1403
1404
1405
# File 'lib/bitferry.rb', line 1402

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

#intact?Boolean

Returns:

  • (Boolean)


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

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

#refers?(volume) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#restore(hash) ⇒ Object



1378
1379
1380
1381
# File 'lib/bitferry.rb', line 1378

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

#rootObject



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

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

#show_statusObject



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

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