WebRI  WebRI::JSONFile

[Validate]
Generated with WebRI Redfish 1.2

JSONFile

TODO: This component is not finished. The actual json produced needs to be fleshed out more, making sure we have all the data we want in there, and theat it is layedout in the optimal structure.

TODO: RDoc has some json related stuff going on. I found RDoc::TopLevel.json_creatable?, so maybe there’s a much better wat to do this component.

Public Instance Methods

all_methods() click to toggle source

All methods.

# File lib/webri/components/jsonfile.rb, line 166
    def all_methods
      @methods ||= (
        list = []
        classes.map do |mod|
          mod.method_list.each do |method|
            list << method
          end
        end
        list
      )
    end
class_tree() click to toggle source

Build class/module namespace tree structure.

# File lib/webri/components/jsonfile.rb, line 42
    def class_tree
      @class_tree ||= generate_class_tree
    end
classes() click to toggle source

— CLASS/MODULES —————————————————-

# File lib/webri/components/jsonfile.rb, line 37
    def classes
      generator.all_classes_and_modules
    end
file_tree() click to toggle source

(Not documented)

# File lib/webri/components/jsonfile.rb, line 89
    def file_tree
      @file_tree ||= generate_file_tree
    end
files() click to toggle source

— FILES ——————————————————

# File lib/webri/components/jsonfile.rb, line 85
    def files
      generator.files
    end
generate() click to toggle source

Save as json.

# File lib/webri/components/jsonfile.rb, line 17
    def generate

puts RDoc::TopLevel.json_creatable?
puts RDoc::TopLevel.to_json

      save_data(class_tree, 'classes.json')
      save_data(file_tree , 'files.json')
      save_data(methods   , 'methods.json')
    end
generate_class_tree() click to toggle source

(Not documented)

# File lib/webri/components/jsonfile.rb, line 46
    def generate_class_tree
      debug_msg "Generating class tree:"
      topclasses = classes.select {|klass| !(RDoc::ClassModule === klass.parent) }
      generate_class_tree_level(topclasses)
    end
generate_class_tree_level(classes) click to toggle source

Recursivly build class/module namespace tree structure

# File lib/webri/components/jsonfile.rb, line 53
    def generate_class_tree_level(classes)
      tree = []
      list = classes.select{|c| c.with_documentation? }
      list = list.sort
      list.each do |c|
        item = c.to_h
        item[:methods] = c.method_list.map{ |m| m.to_h }
        item[:classes] = generate_class_tree_level(c.classes_and_modules)
        tree << item
      end
      tree
    end
generate_file_tree() click to toggle source
# File lib/webri/components/jsonfile.rb, line 94
    def generate_file_tree
      debug_msg "Generating file tree:"
      return {} if files.empty?
      ftree = {}
      files.each do |file|
        path = file.full_name
        generate_file_tree_level(path, file, ftree)
      end
      ftree
    end
generate_file_tree_level(path, file, tree) click to toggle source

(Not documented)

# File lib/webri/components/jsonfile.rb, line 105
    def generate_file_tree_level(path, file, tree)
      parent, *subpath = *path.split(File::SEPARATOR)
      subpath = subpath.join(File::SEPARATOR)
      tree[parent] ||= {}
      e = tree[parent]
      e[:name] = parent
      if subpath.empty?
        e.merge!(file.to_h)
      else
        e[:files] ||= {}
        generate_file_tree_level(subpath, file, e[:files])
      end
    end
save_data(data, file) click to toggle source

Save class tree

# File lib/webri/components/jsonfile.rb, line 28
    def save_data(data, file)
      debug_msg "writing data to %s" % file
      File.open(file, "w", 0644) do |f|
        f.write(data.to_json)
      end unless $dryrun
    end

Disabled; run with --debug to generate this.