Class: Guard::CtagsBundler::CtagsGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/guard/ctags-bundler/ctags_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ CtagsGenerator

Returns a new instance of CtagsGenerator.



8
9
10
# File 'lib/guard/ctags-bundler/ctags_generator.rb', line 8

def initialize(opts = {})
  @opts = opts
end

Instance Method Details

#generate_bundler_tagsObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/guard/ctags-bundler/ctags_generator.rb', line 16

def generate_bundler_tags
  # FIXME: Using bundler API cases issues when guard is executed in the non-bundler environment
  #::Bundler.configure # in case we're not running guard from inside Bundler
  #definition = ::Bundler::Definition.build("Gemfile", "Gemfile.lock", nil)
  #runtime = ::Bundler::Runtime.new(Dir.pwd, definition)
  #paths = runtime.requested_specs.map(&:full_gem_path)

  # this is ugly, but should work with every bundler version
  cmd = <<-CMD
    require('bundler')
    require('bundler/runtime')
    ::Bundler.configure
    definition = ::Bundler::Definition.build('Gemfile', 'Gemfile.lock', nil)
    runtime = ::Bundler::Runtime.new(Dir.pwd, definition)
    paths = runtime.requested_specs.map(&:full_gem_path)
    puts(paths.join(' '))
  CMD
  paths = `ruby -e "#{cmd}"`

  generate_tags(paths.strip, custom_path_for(@opts.fetch(:bundler_tags_file, "gems.tags")))
end

#generate_project_tagsObject



12
13
14
# File 'lib/guard/ctags-bundler/ctags_generator.rb', line 12

def generate_project_tags
  generate_tags(@opts[:src_path] || ".", custom_path_for(@opts.fetch(:project_file, "tags")))
end

#generate_stdlib_tagsObject



38
39
40
# File 'lib/guard/ctags-bundler/ctags_generator.rb', line 38

def generate_stdlib_tags
  generate_tags(stdlib_path, custom_path_for(@opts.fetch(:stdlib_file, "stdlib.tags")))
end