Class: Vernier::Output::Firefox::Categorizer
- Inherits:
-
Object
- Object
- Vernier::Output::Firefox::Categorizer
- Defined in:
- lib/vernier/output/firefox.rb
Defined Under Namespace
Classes: Category
Constant Summary collapse
- RAILS_COMPONENTS =
%w[ activesupport activemodel activerecord actionview actionpack activejob actionmailer actioncable activestorage actionmailbox actiontext railties ]- AVAILABLE_COLORS =
%w[ transparent purple green orange yellow lightblue blue brown magenta red lightred darkgrey grey ]- ORDERED_CATEGORIES =
This is in the order of preference
%w[ Kernel Rails gem Ruby ]
Instance Attribute Summary collapse
-
#categories ⇒ Object
readonly
Returns the value of attribute categories.
Instance Method Summary collapse
- #add_category(name:, **kw) {|category| ... } ⇒ Object
- #categorize(path) ⇒ Object
- #gem_path(*names) ⇒ Object
- #get_category(name) ⇒ Object
-
#initialize ⇒ Categorizer
constructor
A new instance of Categorizer.
- #starts_with(*paths) ⇒ Object
Constructor Details
#initialize ⇒ Categorizer
Returns a new instance of Categorizer.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 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 67 |
# File 'lib/vernier/output/firefox.rb', line 25 def initialize @categories = [] @categories_by_name = {} add_category(name: "Kernel", color: "magenta") do |c| c.add_subcategory( name: "Kernel", matcher: starts_with("<internal") ) end add_category(name: "gem", color: "lightblue") do |c| c.add_subcategory( name: "gem", matcher: starts_with(*Gem.path) ) end add_category(name: "Rails", color: "red") do |c| RAILS_COMPONENTS.each do |subcategory| c.add_subcategory( name: subcategory, matcher: gem_path(subcategory) ) end end add_category(name: "Ruby", color: "purple") do |c| c.add_subcategory( name: "stdlib", matcher: starts_with(RbConfig::CONFIG["rubylibdir"]) ) end add_category(name: "Idle", color: "transparent") add_category(name: "Stalled", color: "transparent") add_category(name: "GC", color: "red") add_category(name: "cfunc", color: "yellow", matcher: "<cfunc>") add_category(name: "Thread", color: "grey") end |
Instance Attribute Details
#categories ⇒ Object (readonly)
Returns the value of attribute categories.
23 24 25 |
# File 'lib/vernier/output/firefox.rb', line 23 def categories @categories end |
Instance Method Details
#add_category(name:, **kw) {|category| ... } ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/vernier/output/firefox.rb', line 69 def add_category(name:, **kw) category = Category.new(@categories.length, name: name, **kw) @categories << category @categories_by_name[name] = category category.add_subcategory(name: "Other") yield category if block_given? category end |
#categorize(path) ⇒ Object
90 91 92 |
# File 'lib/vernier/output/firefox.rb', line 90 def categorize(path) @categories.detect { |category| category.matches?(path) } || @categories.first end |
#gem_path(*names) ⇒ Object
86 87 88 |
# File 'lib/vernier/output/firefox.rb', line 86 def gem_path(*names) %r{\A#{Regexp.union(Gem.path)}/gems/#{Regexp.union(names)}} end |
#get_category(name) ⇒ Object
78 79 80 |
# File 'lib/vernier/output/firefox.rb', line 78 def get_category(name) @categories_by_name[name] end |
#starts_with(*paths) ⇒ Object
82 83 84 |
# File 'lib/vernier/output/firefox.rb', line 82 def starts_with(*paths) %r{\A#{Regexp.union(paths)}} end |