Sha256: a65da19e7e845f4c04a8233d81435192a3a54dc018bc519a22cb76b1d295dddd

Contents?: true

Size: 884 Bytes

Versions: 3

Compression:

Stored size: 884 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.overwrite clean_gemfile_content
    end

    def gem_filepath
      [RailsAssist::Directory.rails_root.path, '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

3 entries across 3 versions & 1 rubygems

Version Path
rails_assist-0.4.2 lib/rails_assist/file/gem_file.rb
rails_assist-0.4.1 lib/rails_assist/file/gem_file.rb
rails_assist-0.4.0 lib/rails_assist/file/gem_file.rb