class Arweave::Directory

Constants

MANIFEST
VERSION

Public Class Methods

new(index: nil, paths: {}) click to toggle source
# File lib/arweave/directory.rb, line 6
def initialize(index: nil, paths: {})
  if index && !paths.keys.include?(index)
    raise PathDoesNotExist.new('`index` path should be included in `paths` argument')
  end

  @index = index
  @paths = paths
end

Public Instance Methods

add(paths) click to toggle source
# File lib/arweave/directory.rb, line 15
def add(paths)
  @paths.merge!(paths)
  self
end
as_json(options = {}) click to toggle source
# File lib/arweave/directory.rb, line 26
def as_json(options = {})
  {
    manifest: MANIFEST,
    version: VERSION,
    **(@index ? { index: { path: @index } } : {}),
    paths: paths
  }
end
paths() click to toggle source
# File lib/arweave/directory.rb, line 20
def paths
  @paths.reduce({}) do |acc, (key, value)|
    acc.merge(key => { id: value })
  end
end
transaction() click to toggle source
# File lib/arweave/directory.rb, line 35
def transaction
  Transaction.new(data: self.to_json).add_tag(name: 'Content-Type', value: 'application/x.arweave-manifest+json')
end