Class: CabbageDoc::Generator
- Inherits:
-
Object
- Object
- CabbageDoc::Generator
show all
- Defined in:
- lib/cabbage_doc/generator.rb
Defined Under Namespace
Classes: Error, InvalidPriority, InvalidType
Constant Summary
collapse
- PRIORITIES =
[:high, :medium, :low].freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(tag = nil) ⇒ Generator
Returns a new instance of Generator.
68
69
70
|
# File 'lib/cabbage_doc/generator.rb', line 68
def initialize(tag = nil)
self.tag = tag
end
|
Instance Attribute Details
#tag ⇒ Object
Returns the value of attribute tag.
66
67
68
|
# File 'lib/cabbage_doc/generator.rb', line 66
def tag
@tag
end
|
Class Method Details
.all ⇒ Object
31
32
33
|
# File 'lib/cabbage_doc/generator.rb', line 31
def all
@_all ||= {}
end
|
.exists?(type) ⇒ Boolean
39
40
41
|
# File 'lib/cabbage_doc/generator.rb', line 39
def exists?(type)
all.has_key?(type)
end
|
.find(type) ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/cabbage_doc/generator.rb', line 51
def find(type)
klass = all[type]
raise InvalidType, type unless klass
klass
end
|
.inherited(klass) ⇒ Object
10
11
12
|
# File 'lib/cabbage_doc/generator.rb', line 10
def inherited(klass)
all[klass.to_s.split('::').last.downcase.to_sym] = klass
end
|
.load! ⇒ Object
59
60
61
62
63
|
# File 'lib/cabbage_doc/generator.rb', line 59
def load!
Dir.glob(File.join(File.dirname(__FILE__), 'generators', '*.rb')).sort.each do |generator|
require(generator)
end
end
|
43
44
45
46
47
48
49
|
# File 'lib/cabbage_doc/generator.rb', line 43
def perform(type, tag = nil)
if type == :all
all.map { |_, klass| klass.new(tag).perform }
else
find(type).new(tag).perform
end
end
|
.priority(value = nil) ⇒ Object
22
23
24
25
26
27
28
29
|
# File 'lib/cabbage_doc/generator.rb', line 22
def priority(value = nil)
if value.is_a?(Symbol)
raise InvalidPriority, value unless PRIORITIES.include?(value)
@_priority = value
else
@_priority
end
end
|
.supports?(type, what) ⇒ Boolean
35
36
37
|
# File 'lib/cabbage_doc/generator.rb', line 35
def supports?(type, what)
!!find(type).public_send(what)
end
|
14
15
16
17
18
19
20
|
# File 'lib/cabbage_doc/generator.rb', line 14
def tags(value = nil)
if value.nil?
@_tags
else
@_tags = !!value
end
end
|
Instance Method Details
72
73
74
|
# File 'lib/cabbage_doc/generator.rb', line 72
def perform
raise NotImplementedError
end
|