Sha256: 5733f78c1090c15e00082a3e1eff4e05a3040f8e5af30ab45a75cabf106de4dc

Contents?: true

Size: 885 Bytes

Versions: 5

Compression:

Stored size: 885 Bytes

Contents

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

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

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

    def gem_filepath
      [RailsAssist::Directory::Root.root_dirpath, 'Gemfile'].file_join
    end
    
    def gem_file
      raise "No Gemfile found at #{gem_filepath}" if !File.exist? gem_filepath
      gem_filepath.new_file
    end

    # def with_gem_file command = nil
    #   return send :"#{command}_gem_file" if command.valid_file_command?
    # 
    #   raise "No Gemfile found at #{gem_filepath}" if gem_filepath.exists?
    #   gem_filepath.new_file
    # end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rails_assist-0.5.2 lib/rails_assist/file/gem_file.rb
rails_assist-0.5.1 lib/rails_assist/file/gem_file.rb
rails_assist-0.5.0 lib/rails_assist/file/gem_file.rb
rails_assist-0.4.4 lib/rails_assist/file/gem_file.rb
rails_assist-0.4.3 lib/rails_assist/file/gem_file.rb