Class: Mattock::YARDExtensions::SettingHandler
- Inherits:
-
YARD::Handlers::Ruby::Base
- Object
- YARD::Handlers::Ruby::Base
- Mattock::YARDExtensions::SettingHandler
show all
- Includes:
- YARD::Parser::Ruby
- Defined in:
- lib/calibrate/yard-extensions.rb
Instance Method Summary
collapse
Instance Method Details
#append_name(sexp, name) ⇒ Object
62
63
64
65
66
67
68
69
|
# File 'lib/calibrate/yard-extensions.rb', line 62
def append_name(sexp, name)
prefix = sexp.jump(:ident, :tstring_content)
if prefix == sexp
raise YARD::Parser::UndocumentableError, sexp.source
end
"#{prefix[0]}.#{name}"
end
|
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/calibrate/yard-extensions.rb', line 51
def (obj)
case obj.type
when :symbol_literal
obj.jump(:ident, :op, :kw, :const)[0]
when :string_literal
obj.jump(:tstring_content)[0]
else
raise YARD::Parser::UndocumentableError, obj.source
end
end
|
#mattock_configurable?(obj) ⇒ Boolean
41
42
43
44
45
46
47
48
49
|
# File 'lib/calibrate/yard-extensions.rb', line 41
def mattock_configurable?(obj)
check_list = obj.inheritance_tree
until check_list.empty?
check_list.each do |co|
return true if [:CascadingDefinition, :Configurable, :Task, :Tasklib, :TaskLib].include? co.name
end
check_list = check_list.find_all{|co| co.respond_to?(:mixins)}.map{|co| co.mixins}.flatten
end
end
|
#process ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/calibrate/yard-extensions.rb', line 88
def process
return unless mattock_configurable?(namespace)
name = (statement.parameters.first)
value = statement.parameters(false)[1]
if !value.nil? and value.type == :fcall and value.jump(:ident)[0] == "nested"
remapped = (value.parameters.first||[]).map do |assoc|
new_name =
append_name(statement.parameters[0], (assoc[0]))
synthetic_setting(new_name, assoc[1])
end
parser.process(remapped)
return
end
setting = YARD::CodeObjects::MethodObject.new(namespace, name) do |set|
unless value.nil?
set['default_value'] = statement.parameters(false)[1].source
end
set.signature = "def #{name}"
if statement..to_s.empty?
set.docstring = "The value of setting #{name}"
else
set.docstring = statement.
end
set.dynamic = true
end
register setting
(namespace[:settings] ||= []) << setting
end
|
#setting_method_name ⇒ Object
71
72
73
|
# File 'lib/calibrate/yard-extensions.rb', line 71
def setting_method_name
"setting"
end
|
#synthetic_setting(name, value = nil) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/calibrate/yard-extensions.rb', line 75
def synthetic_setting(name, value=nil)
args = s( s(:string_literal, s(:string_content, s(:tstring_content, name))))
args << value unless value.nil?
args << false
new_call = s(:fcall, s(:ident, setting_method_name), s(:arg_paren, args))
new_call.line_range = (1..1)
new_call.traverse do |node|
node.full_source ||= ""
end
new_call.full_source = "#{setting_method_name}('#{name}'#{value.nil? ? "" : ", #{value.source}"})"
new_call
end
|