Module: EmberKonacha::GemHelper

Included in:
EmberKonacha::Generators::GuardGenerator, EmberKonacha::Generators::InstallGenerator
Defined in:
lib/generators/ember_konacha/gem_helper.rb

Instance Method Summary collapse

Instance Method Details

#bundle_command(command) ⇒ Object

File railties/lib/rails/generators/app_base.rb, line 241



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/generators/ember_konacha/gem_helper.rb', line 8

def bundle_command(command)
  say_status :run, "bundle #{command}"

  # We are going to shell out rather than invoking Bundler::CLI.new(command)
  # because `rails new` loads the Thor gem and on the other hand bundler uses
  # its own vendored Thor, which could be a different version. Running both
  # things in the same process is a recipe for a night with paracetamol.
  #
  # We use backticks and #print here instead of vanilla #system because it
  # is easier to silence stdout in the existing test suite this way. The
  # end-user gets the bundler commands called anyway, so no big deal.
  #
  # Thanks to James Tucker for the Gem tricks involved in this call.
  print %x[#{Gem.ruby} -rubygems "#{ruby_gems}" #{command}]
end

#bundle_gems!Object



3
4
5
# File 'lib/generators/ember_konacha/gem_helper.rb', line 3

def bundle_gems!
  bundle_command 'install'
end

#gemfileObject



44
45
46
# File 'lib/generators/ember_konacha/gem_helper.rb', line 44

def gemfile
  @gemfile ||= File.open Rails.root.join('Gemfile'), 'r'
end

#gemfile_contentObject



40
41
42
# File 'lib/generators/ember_konacha/gem_helper.rb', line 40

def gemfile_content
  @gemfile_content ||= gemfile.read
end

#has_all_gems?(*names) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/generators/ember_konacha/gem_helper.rb', line 32

def has_all_gems? *names
  names.flatten.all? {|name| has_gem? name }
end

#has_any_gem?(*names) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/generators/ember_konacha/gem_helper.rb', line 28

def has_any_gem? *names
  names.flatten.any? {|name| has_gem? name }
end

#has_gem?(name) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/generators/ember_konacha/gem_helper.rb', line 36

def has_gem? name
  gemfile_content =~ /gem\s+('|")#{name}/
end

#ruby_gemsObject



24
25
26
# File 'lib/generators/ember_konacha/gem_helper.rb', line 24

def ruby_gems
  Gem.bin_path('bundler', 'bundle')
end