Module: RailsAssist::File::Gemfile

Included in:
Special, Special
Defined in:
lib/rails_assist/file/gem_file.rb

Instance Method Summary collapse

Instance Method Details

#clean_gemfileObject



11
12
13
14
# File 'lib/rails_assist/file/gem_file.rb', line 11

def clean_gemfile
  clean_gemfile_content = read_gem_file.gsub(/('|"|end)\s*gem/m, "\\1\ngem")
  read_gem_file.replace clean_gemfile_content
end

#gem_fileObject



20
21
22
23
# File 'lib/rails_assist/file/gem_file.rb', line 20

def gem_file
  raise "No Gemfile found at #{gem_filepath}" if !File.exist? gem_filepath
  gem_filepath.new_file
end

#gem_filepathObject



16
17
18
# File 'lib/rails_assist/file/gem_file.rb', line 16

def gem_filepath
  [RailsAssist::Directory::Root.root_dirpath, 'Gemfile'].file_join
end

#has_gem?(name) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/rails_assist/file/gem_file.rb', line 3

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

#has_gem_version?(name, version = nil) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/rails_assist/file/gem_file.rb', line 7

def has_gem_version? name, version = nil
  read_gem_file =~ /gem\s+('|")#{name}\1,\s*('|")#{version}\2/
end