Class: Quiver::Root

Inherits:
Object
  • Object
show all
Defined in:
lib/quiver/root.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#adapterObject (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.meta['uuid'] ||= SecureRandom.uuid.upcase
  notebook.path = @path + "#{notebook.meta['uuid']}.qvnotebook"
  notebook.adapter = @adapter
  notebook.save
end

#eachObject



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
      meta = JSON.parse(@adapter.load(path + 'meta.json'))
      Notebook.new(meta: 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