class Crossbelt::Plugins::Exporters::Ipfs

Public Class Methods

description() click to toggle source
# File lib/crossbelt/plugins/exporters/ipfs.rb, line 22
def self.description
  'Outputs data on IPFS file system'
end
export(file: nil, contents: nil) click to toggle source
# File lib/crossbelt/plugins/exporters/ipfs.rb, line 35
def self.export(file: nil, contents: nil)
  raise ArgumentError unless file || contents

  begin
    if contents
      file = Tempfile.new
      File.write(file, contents)
    end
    new.add(file)
  ensure
    file.close if file.is_a?(Tempfile)
  end
end
name() click to toggle source
# File lib/crossbelt/plugins/exporters/ipfs.rb, line 18
def self.name
  'ipfs'
end
to_h() click to toggle source
# File lib/crossbelt/plugins/exporters/ipfs.rb, line 26
def self.to_h
  {
    name: name,
    type: type,
    version: version,
    desc: description
  }
end
type() click to toggle source
# File lib/crossbelt/plugins/exporters/ipfs.rb, line 10
def self.type
  'exporter'
end
version() click to toggle source
# File lib/crossbelt/plugins/exporters/ipfs.rb, line 14
def self.version
  '0.0.1'
end

Public Instance Methods

add(file) click to toggle source
# File lib/crossbelt/plugins/exporters/ipfs.rb, line 65
def add(file)
  node = client.add(File.expand_path(file))
  node.hashcode
end
client() click to toggle source
# File lib/crossbelt/plugins/exporters/ipfs.rb, line 49
def client
  @client ||= IPFS::Client.default
end
ls(node) click to toggle source
# File lib/crossbelt/plugins/exporters/ipfs.rb, line 61
def ls(node)
  client.ls(node)
end
pin_rm(node) click to toggle source
# File lib/crossbelt/plugins/exporters/ipfs.rb, line 53
def pin_rm(node)
  JSON.parse client.pin_rm(node)
end
read(node) click to toggle source
# File lib/crossbelt/plugins/exporters/ipfs.rb, line 57
def read(node)
  client.cat(node)
end