Class: Docs::Doc

Inherits:
Object
  • Object
show all
Defined in:
lib/docs/core/doc.rb

Direct Known Subclasses

Scraper

Constant Summary collapse

INDEX_FILENAME =
'index.json'
DB_FILENAME =
'db.json'

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDoc

Returns a new instance of Doc

Raises:

  • (NotImplementedError)

82
83
84
# File 'lib/docs/core/doc.rb', line 82

def initialize
  raise NotImplementedError, "#{self.class} is an abstract class and cannot be instantiated." if self.class.abstract
end

Class Attribute Details

.abstractObject

Returns the value of attribute abstract


7
8
9
# File 'lib/docs/core/doc.rb', line 7

def abstract
  @abstract
end

.nameObject

Returns the value of attribute name


7
8
9
# File 'lib/docs/core/doc.rb', line 7

def name
  @name
end

.slugObject

Returns the value of attribute slug


7
8
9
# File 'lib/docs/core/doc.rb', line 7

def slug
  @slug
end

.typeObject

Returns the value of attribute type


7
8
9
# File 'lib/docs/core/doc.rb', line 7

def type
  @type
end

.versionObject

Returns the value of attribute version


7
8
9
# File 'lib/docs/core/doc.rb', line 7

def version
  @version
end

Class Method Details

.as_jsonObject


33
34
35
36
37
38
39
40
# File 'lib/docs/core/doc.rb', line 33

def as_json
  { name: name,
    slug: slug,
    type: type,
    version: version,
    index_path: index_path,
    db_path: db_path }
end

.db_pathObject


29
30
31
# File 'lib/docs/core/doc.rb', line 29

def db_path
  File.join path, DB_FILENAME
end

.index_pathObject


25
26
27
# File 'lib/docs/core/doc.rb', line 25

def index_path
  File.join path, INDEX_FILENAME
end

.inherited(subclass) ⇒ Object


9
10
11
# File 'lib/docs/core/doc.rb', line 9

def inherited(subclass)
  subclass.type = type
end

.pathObject


21
22
23
# File 'lib/docs/core/doc.rb', line 21

def path
  slug
end

.store_page(store, id) ⇒ Object


42
43
44
45
46
47
48
49
50
51
# File 'lib/docs/core/doc.rb', line 42

def store_page(store, id)
  store.open(path) do
    if page = new.build_page(id) and store_page?(page)
      store.write page[:store_path], page[:output]
      true
    else
      false
    end
  end
end

.store_pages(store) ⇒ Object


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/docs/core/doc.rb', line 53

def store_pages(store)
  index = EntryIndex.new
  pages = PageDb.new

  store.replace(path) do
    new.build_pages do |page|
      next unless store_page?(page)
      store.write page[:store_path], page[:output]
      index.add page[:entries]
      pages.add page[:path], page[:output]
    end

    if index.present?
      store.write INDEX_FILENAME, index.to_json
      store.write DB_FILENAME, pages.to_json
      true
    else
      false
    end
  end
end

Instance Method Details

#build_page(id, &block) ⇒ Object

Raises:

  • (NotImplementedError)

86
87
88
# File 'lib/docs/core/doc.rb', line 86

def build_page(id, &block)
  raise NotImplementedError
end

#build_pages(&block) ⇒ Object

Raises:

  • (NotImplementedError)

90
91
92
# File 'lib/docs/core/doc.rb', line 90

def build_pages(&block)
  raise NotImplementedError
end