Class: Arweave::Directory
- Inherits:
-
Object
- Object
- Arweave::Directory
- Defined in:
- lib/arweave/directory.rb
Constant Summary collapse
- MANIFEST =
'arweave/paths'
- VERSION =
'0.1.0'
Instance Method Summary collapse
- #add(paths) ⇒ Object
- #as_json(options = {}) ⇒ Object
-
#initialize(index: nil, paths: {}) ⇒ Directory
constructor
A new instance of Directory.
- #paths ⇒ Object
- #transaction ⇒ Object
Constructor Details
#initialize(index: nil, paths: {}) ⇒ Directory
Returns a new instance of Directory.
6 7 8 9 10 11 12 13 |
# 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 |
Instance Method Details
#add(paths) ⇒ Object
15 16 17 18 |
# File 'lib/arweave/directory.rb', line 15 def add(paths) @paths.merge!(paths) self end |
#as_json(options = {}) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/arweave/directory.rb', line 26 def as_json( = {}) { manifest: MANIFEST, version: VERSION, **(@index ? { index: { path: @index } } : {}), paths: paths } end |
#paths ⇒ Object
20 21 22 23 24 |
# File 'lib/arweave/directory.rb', line 20 def paths @paths.reduce({}) do |acc, (key, value)| acc.merge(key => { id: value }) end end |
#transaction ⇒ Object
35 36 37 |
# 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 |