Class: Quiver::Root
- Inherits:
-
Object
- Object
- Quiver::Root
- Defined in:
- lib/quiver/root.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
Instance Method Summary collapse
- #add(notebook) ⇒ Object
- #each ⇒ Object
-
#initialize(adapter) ⇒ Root
constructor
A new instance of Root.
- #notebook(name) ⇒ Object
Constructor Details
#initialize(adapter) ⇒ Root
Returns a new instance of Root.
4 5 6 |
# File 'lib/quiver/root.rb', line 4 def initialize(adapter) @adapter = adapter end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
3 4 5 |
# File 'lib/quiver/root.rb', line 3 def adapter @adapter end |
Instance Method Details
#add(notebook) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/quiver/root.rb', line 22 def add(notebook) raise 'this notebook already added' if notebook.path notebook.['uuid'] ||= SecureRandom.uuid.upcase notebook.path = @path + "#{notebook.['uuid']}.qvnotebook" notebook.adapter = @adapter notebook.save end |
#each ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/quiver/root.rb', line 7 def each @each_cache = {} @adapter.each('.', 'qvnotebook') do |path| @each_cache[path] ||= begin = JSON.parse(@adapter.load(path + 'meta.json')) Notebook.new(meta: , path: path, root: self) end yield @each_cache[path] end end |
#notebook(name) ⇒ Object
17 18 19 20 21 |
# File 'lib/quiver/root.rb', line 17 def notebook(name) each do |notebook| return notebook if notebook.name == name end end |