Class: Gemist::Gemfile

Inherits:
Object
  • Object
show all
Defined in:
lib/gemist.rb

Overview

A definition of a project Gemfile manifest.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contents, lockfile) ⇒ Gemfile

Returns a new instance of Gemfile.



89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/gemist.rb', line 89

def initialize(contents, lockfile)
  instance_eval contents

  # Parse the lockfile
  if lockfile
    lockfile.split("\n").each { |s|
      name, version = s.scan(/^    ([^ ]+) \(([0-9].*?)\)$/).first
      gem = self[name]
      gem.versions = [version]  if gem
    }
  end
end

Class Method Details

.exists?Boolean

Checks if the project has a Gemfile manifest.

Returns:

  • (Boolean)


80
81
82
# File 'lib/gemist.rb', line 80

def self.exists?
  !!path
end

.loadObject

Returns a Gemfile instance made from the project’s manifest.



85
86
87
# File 'lib/gemist.rb', line 85

def self.load
  new(File.read(path), lockfile_contents)  if exists?
end

.lockfile_pathObject



75
76
77
# File 'lib/gemist.rb', line 75

def self.lockfile_path
  Dir["./{Gemistfile,Gemfile,Isolate}.lock"].first
end

.pathObject

Returns the path of the project’s Gemfile manifest, or nil if not available.



67
68
69
70
71
72
73
# File 'lib/gemist.rb', line 67

def self.path
  %w(GEMFILE BUNDLER_GEMFILE).each do |spec|
    return ENV[spec]  if ENV[spec] && File.exists?(ENV[spec])
  end

  Dir["./{Gemistfile,Gemfile,Isolate}"].first
end

Instance Method Details

#[](name) ⇒ Object

Returns a gem



103
104
105
# File 'lib/gemist.rb', line 103

def [](name)
  gems.select { |gem| gem.name == name }.first
end

#gemsObject

The list of gems the Gemfile. Returns an array of Gem instances.



108
109
110
# File 'lib/gemist.rb', line 108

def gems()
  @gems ||= Array.new
end

#gems_for(env) ⇒ Object

Returns a list of Gem instances for the given environment.



113
114
115
# File 'lib/gemist.rb', line 113

def gems_for(env)
  gems.select { |g| g.group == nil || g.group.include?(env.to_s.to_sym) }
end