Class: OpenAPISourceTools::Docs

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi/sourcetools/docs.rb

Overview

To hold documents loaded via command-line. Provides attribute accessor methods for each document. Exposed via Gen.d to tasks.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDocs

Returns a new instance of Docs.



13
14
15
# File 'lib/openapi/sourcetools/docs.rb', line 13

def initialize
  @docs = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/openapi/sourcetools/docs.rb', line 17

def method_missing(method_name, *args)
  name = method_name.to_s
  if name.end_with?('=')
    name = name[0...(name.size - 1)]
    super unless @docs.key?(name)
    @docs[name] = args.first
    return args.first
  end
  super unless @docs.key?(name)
  @docs[name]
end

Instance Attribute Details

#docsObject (readonly)

Returns the value of attribute docs.



11
12
13
# File 'lib/openapi/sourcetools/docs.rb', line 11

def docs
  @docs
end

Instance Method Details

#add(name, content) ⇒ Object



35
36
37
38
39
# File 'lib/openapi/sourcetools/docs.rb', line 35

def add(name, content)
  return false if docs.key?(name)
  @docs[name] = content
  true
end

#respond_to_missing?(method_name, *args) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
# File 'lib/openapi/sourcetools/docs.rb', line 29

def respond_to_missing?(method_name, *args)
  name = method_name.to_s
  name = name[0...(name.size - 1)] if name.end_with?('=')
  @docs.key?(name) || super
end