Class: Crossbelt::Plugins::Exporters::Ipfs
- Inherits:
-
Object
- Object
- Crossbelt::Plugins::Exporters::Ipfs
- Defined in:
- lib/crossbelt/plugins/exporters/ipfs.rb
Class Method Summary collapse
- .description ⇒ Object
- .export(file: nil, contents: nil) ⇒ Object
- .name ⇒ Object
- .to_h ⇒ Object
- .type ⇒ Object
- .version ⇒ Object
Instance Method Summary collapse
Class Method Details
.description ⇒ Object
22 23 24 |
# File 'lib/crossbelt/plugins/exporters/ipfs.rb', line 22 def self.description 'Outputs data on IPFS file system' end |
.export(file: nil, contents: nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# 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 ⇒ Object
18 19 20 |
# File 'lib/crossbelt/plugins/exporters/ipfs.rb', line 18 def self.name 'ipfs' end |
.to_h ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/crossbelt/plugins/exporters/ipfs.rb', line 26 def self.to_h { name: name, type: type, version: version, desc: description } end |
.type ⇒ Object
10 11 12 |
# File 'lib/crossbelt/plugins/exporters/ipfs.rb', line 10 def self.type 'exporter' end |
.version ⇒ Object
14 15 16 |
# File 'lib/crossbelt/plugins/exporters/ipfs.rb', line 14 def self.version '0.0.1' end |
Instance Method Details
#add(file) ⇒ Object
65 66 67 68 |
# File 'lib/crossbelt/plugins/exporters/ipfs.rb', line 65 def add(file) node = client.add(File.(file)) node.hashcode end |
#client ⇒ Object
49 50 51 |
# File 'lib/crossbelt/plugins/exporters/ipfs.rb', line 49 def client @client ||= IPFS::Client.default end |
#ls(node) ⇒ Object
61 62 63 |
# File 'lib/crossbelt/plugins/exporters/ipfs.rb', line 61 def ls(node) client.ls(node) end |
#pin_rm(node) ⇒ Object
53 54 55 |
# File 'lib/crossbelt/plugins/exporters/ipfs.rb', line 53 def pin_rm(node) JSON.parse client.pin_rm(node) end |
#read(node) ⇒ Object
57 58 59 |
# File 'lib/crossbelt/plugins/exporters/ipfs.rb', line 57 def read(node) client.cat(node) end |