Class: Gem::Tasks::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/rubygems/tasks/project.rb

Constant Summary collapse

SCM_DIRS =

Supported SCMs and their control directories.

{
  git: '.git',
  hg:  '.hg',
  svn: '.svn'
}
PKG_DIR =

The pkg/ directory.

'pkg'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root = Dir.pwd) ⇒ Project

Initializes the project.

Parameters:

  • root (String) (defaults to: Dir.pwd)

    The root directory of the project.


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/rubygems/tasks/project.rb', line 72

def initialize(root=Dir.pwd)
  @root = root
  @name = File.basename(@root)

  @scm, _ = SCM_DIRS.find do |scm,dir|
              File.directory?(File.join(@root,dir))
            end

  Dir.chdir(@root) do
    @gemspecs = Hash[Dir['*.gemspec'].map { |path|
      [File.basename(path,'.gemspec'), Specification.load(path)]
    }]
  end

  @primary_gemspec = if @gemspecs.has_key?(@name)
                       @name
                     else
                       @gemspecs.keys.sort.first
                     end

  @builds = {}

  @gemspecs.each do |name,gemspec|
    @builds[name] = Hash.new do |packages,format|
      packages[format] = File.join(PKG_DIR,"#{gemspec.full_name}.#{format}")
    end
  end

  @bundler = File.file?(File.join(@root,'Gemfile'))
end

Instance Attribute Details

#buildsHash{String => Hash{String => String}} (readonly)

The builds and their packages.

Returns:

  • (Hash{String => Hash{String => String}})

    The hash of builds and their respective packages.


56
57
58
# File 'lib/rubygems/tasks/project.rb', line 56

def builds
  @builds
end

#gemspecsHash{String => Gem::Specification} (readonly)

The builds and gemspecs of the project.

Returns:

  • (Hash{String => Gem::Specification})

    The hash of builds and their gemspecs.


48
49
50
# File 'lib/rubygems/tasks/project.rb', line 48

def gemspecs
  @gemspecs
end

#nameString (readonly)

The name of the project.

Returns:

  • (String)

    The project name.


34
35
36
# File 'lib/rubygems/tasks/project.rb', line 34

def name
  @name
end

#primary_gemspecString (readonly)

The name of the primary gemspec.

Returns:

  • (String)

    The gemspec name.


64
65
66
# File 'lib/rubygems/tasks/project.rb', line 64

def primary_gemspec
  @primary_gemspec
end

#rootString (readonly)

The project directory.

Returns:

  • (String)

    The path to the project.


26
27
28
# File 'lib/rubygems/tasks/project.rb', line 26

def root
  @root
end

#scmSymbol? (readonly)

Returns The SCM the project is using.

Returns:

  • (Symbol, nil)

    The SCM the project is using.


40
41
42
# File 'lib/rubygems/tasks/project.rb', line 40

def scm
  @scm
end

Class Method Details

.directoriesHash{String => Project}

Maps project directories to projects.

Returns:

  • (Hash{String => Project})

    Project directories and project objects.


128
129
130
131
132
# File 'lib/rubygems/tasks/project.rb', line 128

def self.directories
  @@directories ||= Hash.new do |hash,key|
    hash[key] = new(key)
  end
end

Instance Method Details

#bundler?Boolean

Specifies whether the project uses Bundler.

Returns:

  • (Boolean)

139
140
141
# File 'lib/rubygems/tasks/project.rb', line 139

def bundler?
  @bundler
end

#gemspec(name = nil) ⇒ Gem::Specification

Retrieves a gemspec for the project.

Parameters:

  • name (String) (defaults to: nil)

    (@primary_gemspec) The gemspec name to retrieve.

Returns:

  • (Gem::Specification)

    The requested gemspec.


112
113
114
115
116
117
118
119
120
# File 'lib/rubygems/tasks/project.rb', line 112

def gemspec(name=nil)
  name ||= @primary_gemspec

  unless @gemspecs.has_key?(name)
    raise(ArgumentError,"unknown gemspec: #{name}")
  end

  return @gemspecs[name]
end