Class: WebTools::CodeBrowser

Inherits:
Tool
  • Object
show all
Defined in:
lib/web_tools/code_browser.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Tool

display_name, dont_show!, dont_show?, file_name, inherited, subclasses

Methods included from Support::ServiceHelper

included

Class Method Details

.descriptionObject



9
10
11
# File 'lib/web_tools/code_browser.rb', line 9

def self.description
  'Browse Namespaces, Classes, and Methods'
end

Instance Method Details

#class_cat_listObject



78
79
80
81
82
83
84
# File 'lib/web_tools/code_browser.rb', line 78

def class_cat_list
  filter = (@dict || @package || reflect(Object))
  names = []
  class_cat_list_for(filter, names)
  @class_category ||= filter
  names.sort
end

#class_cat_list_for(klassmirror, ary) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/web_tools/code_browser.rb', line 86

def class_cat_list_for(klassmirror, ary)
  klassmirror.nested_classes.each do |klass|
    path = klass.name.gsub("::", "-")
    unless ary.include? path
      ary << path
      if @class_category.nil? && params['classCat'] == path
        @class_category = klass
      end
      class_cat_list_for(klass, ary)
    end
  end
end

#class_listArray

Returns a sorted list of class and module names in the Ruby Namespace

Returns:

  • (Array)

    sorted list of class and module names found in the Ruby namespace hierarchy.



103
104
105
106
107
# File 'lib/web_tools/code_browser.rb', line 103

def class_list
  @klass = reflect(Object).constant(params["klass"]).value if params["klass"]
  @klass = @klass.singleton_class if @klass && params["isMeta"]
  (@class_category.nested_classes + [@class_category]).collect(&:name).uniq.sort
end

#dict_listObject



68
69
70
71
72
73
74
75
76
# File 'lib/web_tools/code_browser.rb', line 68

def dict_list
  return [] unless params['isDictsTab']
  pkgs = ["Object"]
  reflect(Object).nested_classes.each do |k|
    pkgs << k.name if k.nested_classes.any?
    @dict = k if @dict.nil? && params['dict'] == k.name
  end
  pkgs.compact.uniq.sort
end

#implementor_listObject



124
125
126
127
128
129
130
131
132
# File 'lib/web_tools/code_browser.rb', line 124

def implementor_list
  selected = params["implementor"]
  return [] if @super_list.nil? || @super_list.empty?
  list = @super_list.select do |c|
    c.methods.include?(@selector)
  end
  @implementor = list.detect {|e| e.name == selected } || @klass
  list.collect(&:name)
end

#methodObject



134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/web_tools/code_browser.rb', line 134

def method
  return nil unless @implementor && @selector
  nil.pause if Module === @implementor
  @method = @implementor.method(@selector)
  { "dictionaryName" => "",
    "className" => @klass.name,
    "isMeta" => params["isMeta"],
    "category" => "",
    "selector" => @selector,
    "source" => @method.source,
    "stepPoints" => @method.step_offsets,
    "sends" => @method.send_offsets }
end

#method_listObject



148
149
150
151
152
153
154
# File 'lib/web_tools/code_browser.rb', line 148

def method_list
  selected = params["selector"]
  return [] if @super_list.nil? || @super_list.empty?
  list = @super_class.methods
  @selector = selected if list.include? selected
  list.sort
end

#response_for_classObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/web_tools/code_browser.rb', line 41

def response_for_class
  # return nil if params["selector"]
  # return nil unless params["request"]
  # begin
  #   result = eval(params["request"])
  #   if result.is_a? Module
  #     return nil unless result.namespace
  #     response = { "dict" => result.namespace.my_class.inspect,
  #       "classCat" => nil,
  #       "klass" => result.inspect,
  #       "isMeta" => false,
  #       "superClass" => result.inspect,
  #       "methodCat" => nil,
  #       "selector" => nil,
  #       "implementor" => nil,
  #       "action" => "klass" }
  #     response.each {|k,v| params[k] = v }
  #     response
  #   else
  #     nil
  #   end
  # rescue Exception => e
  #   { "action" => "klass",
  #     "error" => [e.class.inspect, e.message] }
  # end
end

#super_listObject



109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/web_tools/code_browser.rb', line 109

def super_list
  return [] if @klass.nil?
  if params["superClass"]
    super_class = non_meta_name(params["superClass"])
    @super_class = reflect(Object).constant(super_class).value
    if super_class != params["superClass"]
      @super_class = @super_class.singleton_class
    end
  else
    @super_class = @klass
  end
  @super_list = @klass.ancestors.reverse
  @super_list.collect(&:name)
end