Class: APISpec::Node
- Inherits:
-
Object
show all
- Defined in:
- lib/apispec/node.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, &block) ⇒ Node
Returns a new instance of Node.
5
6
7
8
|
# File 'lib/apispec/node.rb', line 5
def initialize(name, &block)
@name = name
instance_eval(&block) if block_given?
end
|
Instance Attribute Details
Returns the value of attribute name.
3
4
5
|
# File 'lib/apispec/node.rb', line 3
def name
@name
end
|
Returns the value of attribute parent.
2
3
4
|
# File 'lib/apispec/node.rb', line 2
def parent
@parent
end
|
Instance Method Details
#full_name ⇒ Object
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/apispec/node.rb', line 22
def full_name
namespace = @name
current_parent = self.parent
while current_parent
break if current_parent.root?
namespace = "#{current_parent.name}.#{namespace}"
current_parent = current_parent.parent
end
namespace
end
|
#node_path ⇒ Object
14
15
16
|
# File 'lib/apispec/node.rb', line 14
def node_path
@name ? "#{@name.downcase}" : "apispec"
end
|
#root? ⇒ Boolean
18
19
20
|
# File 'lib/apispec/node.rb', line 18
def root?
@parent.nil?
end
|
#to_html(generator) ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/apispec/node.rb', line 45
def to_html(generator)
@generator = generator
if self.respond_to? :resolve_references!
resolve_references!(generator.namespace)
end
generator.template(binding, self.class.name.downcase.gsub("apispec::", ""))
end
|
walk the tree up and return a complete path to the node
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/apispec/node.rb', line 34
def to_path
namespace = node_path
current_parent = self.parent
while current_parent
break if current_parent.root?
namespace = File.join(current_parent.node_path, namespace)
current_parent = current_parent.parent
end
"#{namespace}.html"
end
|
10
11
12
|
# File 'lib/apispec/node.rb', line 10
def to_s
"#{self.class.name.gsub("APISpec::", "")} #{@name}"
end
|