Class: Gemist::Gemfile
- Inherits:
-
Object
- Object
- Gemist::Gemfile
- Defined in:
- lib/gemist.rb
Overview
A definition of a project Gemfile manifest.
Class Method Summary collapse
-
.exists? ⇒ Boolean
Checks if the project has a Gemfile manifest.
-
.load ⇒ Object
Returns a Gemfile instance made from the project’s manifest.
- .lockfile_path ⇒ Object
-
.path ⇒ Object
Returns the path of the project’s Gemfile manifest, or
nilif not available.
Instance Method Summary collapse
-
#[](name) ⇒ Object
Returns a gem.
-
#gems ⇒ Object
The list of gems the Gemfile.
-
#gems_for(env) ⇒ Object
Returns a list of Gem instances for the given environment.
-
#initialize(contents, lockfile) ⇒ Gemfile
constructor
A new instance of Gemfile.
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.
80 81 82 |
# File 'lib/gemist.rb', line 80 def self.exists? !!path end |
.load ⇒ Object
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_path ⇒ Object
75 76 77 |
# File 'lib/gemist.rb', line 75 def self.lockfile_path Dir["./{Gemistfile,Gemfile,Isolate}.lock"].first end |
.path ⇒ Object
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 |
#gems ⇒ Object
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 |