Class: Dictum::Documenter

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/dictum/documenter.rb

Overview

Singleton class that gathers the documentation and stores it as a hash/json

Constant Summary collapse

TEMPFILE_NAME =
'dictum_temp.json'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDocumenter

Returns a new instance of Documenter.



14
15
16
17
# File 'lib/dictum/documenter.rb', line 14

def initialize
  reset_data
  @tempfile_path = "#{Dir.tmpdir}/#{TEMPFILE_NAME}"
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



11
12
13
# File 'lib/dictum/documenter.rb', line 11

def data
  @data
end

#tempfile_pathObject (readonly)

Returns the value of attribute tempfile_path.



11
12
13
# File 'lib/dictum/documenter.rb', line 11

def tempfile_path
  @tempfile_path
end

Instance Method Details

#endpoint(arguments = {}) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/dictum/documenter.rb', line 30

def endpoint(arguments = {})
  resource = arguments[:resource]
  endpoint = arguments[:endpoint]
  return if resource.nil? || endpoint.nil?
  resource(name: resource) unless resources.key? resource
  resources[resource][:endpoints] << arguments_hash(arguments)
  update_temp
end

#reset_dataObject



39
40
41
42
43
# File 'lib/dictum/documenter.rb', line 39

def reset_data
  @data = {
    resources: {}
  }
end

#resource(arguments = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/dictum/documenter.rb', line 19

def resource(arguments = {})
  return if arguments.nil?
  name = arguments[:name]
  description = arguments[:description]
  return if name.nil?
  resources[name] ||= {}
  resources[name][:description] = description if description
  resources[name][:endpoints] ||= []
  update_temp
end