Class: Dictum::Documenter
- Inherits:
-
Object
- Object
- Dictum::Documenter
- Includes:
- Singleton
- Defined in:
- lib/dictum/documenter.rb
Overview
Singleton class that gathers the documentation and stores it as a hash/json
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#tempfile_path ⇒ Object
readonly
Returns the value of attribute tempfile_path.
Instance Method Summary collapse
- #endpoint(arguments = {}) ⇒ Object
- #error_code(error = {}) ⇒ Object
-
#initialize ⇒ Documenter
constructor
A new instance of Documenter.
- #reset_data ⇒ Object
- #resource(arguments = {}) ⇒ Object
Constructor Details
#initialize ⇒ Documenter
Returns a new instance of Documenter.
13 14 15 16 |
# File 'lib/dictum/documenter.rb', line 13 def initialize reset_data @tempfile_path = Dictum::TEMPFILE_PATH end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
11 12 13 |
# File 'lib/dictum/documenter.rb', line 11 def data @data end |
#tempfile_path ⇒ Object (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
29 30 31 32 33 34 35 36 |
# File 'lib/dictum/documenter.rb', line 29 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 |
#error_code(error = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/dictum/documenter.rb', line 38 def error_code(error = {}) return if error.nil? || !error.is_a?(Hash) error_hash = { code: error[:code] || Dictum::MISSING_MESSAGE, message: error[:message] || '', description: error[:description] || '' } error_codes << error_hash update_temp end |
#reset_data ⇒ Object
49 50 51 52 53 54 |
# File 'lib/dictum/documenter.rb', line 49 def reset_data @data = { resources: {}, error_codes: [] } end |
#resource(arguments = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/dictum/documenter.rb', line 18 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 && description.is_a?(String) resources[name][:endpoints] ||= [] update_temp end |