Skip to content

Instantly share code, notes, and snippets.

@haiitch
Created March 4, 2018 01:28
Show Gist options
  • Save haiitch/ddd099c3fd4c88c4a9b9c5da997a6ac0 to your computer and use it in GitHub Desktop.
Save haiitch/ddd099c3fd4c88c4a9b9c5da997a6ac0 to your computer and use it in GitHub Desktop.
a trivial dsl for ipfs dag handling
dago1 = DAGObject.new
puts "DIR #{dago1.cid}"
dag1 = DAG.new( { a: 1, b: 2, c: 3 } )
puts "DAG #{dag1.cid}"
dag2 = DAG.new( { artist: "Ramones", phrase: "Hey, ho! Let's go!" } )
puts "DAG #{dag2.cid}"
dag3 = DAG.new( { country: "Australia", capital: "Canberra" } )
puts "DAG #{dag3.cid}"
dago1.add_link( "abc", dag1.cid )
dago1.add_link( "ramones", dag2.cid )
dago1.add_link( "city", dag3.cid )
dago2 = DAGObject.new
dago2.add_link( "bands", dago1.cid )
dag2 = DAG.new( { artist: "Ramones", phrase: "Hey ho let's go", touring: { "/" => dag3.cid } } )
dago1.rm_link("ramones")
dago1.add_link("ramones", dag2.cid)
dago2.rm_link("bands")
dago2.add_link("bands", dago1.cid)
puts dago2.cid
pp dago2.>>(:bands)
puts "touring: "
touring = dago2.>>(:bands).>>(:ramones).>>(:touring)
puts dag2.node.artist + " are opening their " + touring.node.country + " tour in " + touring.node.capital + " tonight."
puts dago2.>>(:bands).>>(:city)[:capital]
puts dago2.cid
@haiitch
Copy link
Author

haiitch commented Mar 4, 2018

alternative block syntax

dago1.patch {
add_link( "abc", dag1.cid )
add_link( "ramones", dag2.cid )
add_link( "city", dag3.cid )
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment