class Mattock::YARDExtensions::SettingHandler
Public Instance Methods
append_name(sexp, name)
click to toggle source
# File lib/mattock/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
extract_name(obj)
click to toggle source
# File lib/mattock/yard_extensions.rb, line 51 def extract_name(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)
click to toggle source
# File lib/mattock/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()
click to toggle source
# File lib/mattock/yard_extensions.rb, line 88 def process return unless mattock_configurable?(namespace) #filter further based on NS === Configurable... name = extract_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], extract_name(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.comments.to_s.empty? set.docstring = "The value of setting #{name}" else set.docstring = statement.comments end set.dynamic = true end register setting (namespace[:settings] ||= []) << setting end
setting_method_name()
click to toggle source
# File lib/mattock/yard_extensions.rb, line 71 def setting_method_name "setting" end
synthetic_setting(name, value=nil)
click to toggle source
# File lib/mattock/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