Class: Zed::Rails::Jumper::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/zed/rails/jumper/cli.rb

Defined Under Namespace

Classes: ControllerFinder, ViewFinder

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/zed/rails/jumper/cli.rb', line 16

def self.exit_on_failure?
  true
end

.startObject



9
10
11
12
13
14
# File 'lib/zed/rails/jumper/cli.rb', line 9

def self.start(*)
  super
rescue Thor::InvocationError, ArgumentError, Errno::ENOENT, IOError => exc
  warn String(exc)
  exit(1)
end

Instance Method Details

#controllerObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/zed/rails/jumper/cli.rb', line 44

def controller
  view_file = options[:path]
  rails_root = options[:root]

  controller_finder = ControllerFinder.new(view_file, rails_root)
  result = controller_finder.find_controller_and_action

  if result
    # Open the controller file in Zed
    system("zed", result[:controller_file])
  else
    warn "No corresponding controller/action found"
    exit 1
  end
end

#lookupObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/zed/rails/jumper/cli.rb', line 24

def lookup
  current_file = options[:path]
  rails_root = options[:root]
  current_line = options[:line]
  
  view_finder = ViewFinder.new(current_file, rails_root, current_line)
  associated_views = view_finder.find_associated_views
  
  if associated_views.any?
    # Open the first view file found in Zed
    system("zed", associated_views.first)
  else
    warn "No associated views found"
    exit 1
  end
end