Class: PartialFinder::Runner
- Inherits:
-
Object
- Object
- PartialFinder::Runner
- Defined in:
- lib/partial_finder/runner.rb
Instance Attribute Summary collapse
-
#partial ⇒ Object
readonly
Returns the value of attribute partial.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Class Method Summary collapse
Instance Method Summary collapse
- #debug ⇒ Object
- #default_search_root ⇒ Object
-
#initialize(partial, search_root = nil) ⇒ Runner
constructor
A new instance of Runner.
- #print ⇒ Object
Constructor Details
#initialize(partial, search_root = nil) ⇒ Runner
Returns a new instance of Runner.
5 6 7 8 |
# File 'lib/partial_finder/runner.rb', line 5 def initialize(partial, search_root = nil) @root = search_root || default_search_root @partial = partial end |
Instance Attribute Details
#partial ⇒ Object (readonly)
Returns the value of attribute partial.
3 4 5 |
# File 'lib/partial_finder/runner.rb', line 3 def partial @partial end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
3 4 5 |
# File 'lib/partial_finder/runner.rb', line 3 def root @root end |
Class Method Details
.help ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/partial_finder/runner.rb', line 40 def self.help <<-MSG.colorize(:blue) Partial Finder is a tool that helps link a given partial with the controllers and routes that render it. It works by making assumptions about Rail's rendering conventions and greping through the application code and routes. Conditional rendering logic is not considered. If a view, partial, or controller appears in the output list, this is only a statement that said file MAY render the partial under certain conditions. While it should handle all common use cases, it doesn't account for every possible edge case and manual greping may still be needed. Task: Find Usage: rake partial_finder:find\\['path/to/_partial.html.erb'\\] Outputs all render chains and tries to match each partial with any controllers and routes that eventually render it. Task: Debug Usage: rake partial_finder:debug\\['path/to/_partial.html.erb'\\] Contains the same output as Find but with additional intermediate steps that can be used to help validate the final results. MSG end |
Instance Method Details
#debug ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/partial_finder/runner.rb', line 18 def debug puts "\n\nStarting the partial finder in debug mode for #{partial} in #{@root}\n\n".colorize(:green) links = LinkSet.new(@partial, @root, debug_mode: true) graph = Graph.new(links) agraph = AssumptionGraph.new(links) puts "" puts "=== Set of Links ===".colorize(:blue) puts links.map{ |li| li.to_s }.join("\n") puts "" puts "=== Chains without Assumptions ===".colorize(:blue) puts Printer.new(graph).string puts "" puts "=== Full Render Chains ===".colorize(:blue) puts Printer.new(agraph).string end |
#default_search_root ⇒ Object
36 37 38 |
# File 'lib/partial_finder/runner.rb', line 36 def default_search_root PartialFinder.default_root + "/app" end |
#print ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/partial_finder/runner.rb', line 10 def print puts "\n\nStarting the partial finder for #{partial} in #{@root}\n\n".colorize(:green) Printer.new( AssumptionGraph.from(@partial, @root) ).string end |