Class: Gem::Tasks::Project Private

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

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

SCM_DIRS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Supported SCMs and their control directories.

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

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The pkg/ directory.

'pkg'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root = Dir.pwd) ⇒ Project

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes the project.

Parameters:

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

    The root directory of the project.



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
102
103
# File 'lib/rubygems/tasks/project.rb', line 74

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)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The builds and their packages.

Returns:

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

    The hash of builds and their respective packages.



58
59
60
# File 'lib/rubygems/tasks/project.rb', line 58

def builds
  @builds
end

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The builds and gemspecs of the project.

Returns:

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

    The hash of builds and their gemspecs.



50
51
52
# File 'lib/rubygems/tasks/project.rb', line 50

def gemspecs
  @gemspecs
end

#nameString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The name of the project.

Returns:

  • (String)

    The project name.



36
37
38
# File 'lib/rubygems/tasks/project.rb', line 36

def name
  @name
end

#primary_gemspecString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The name of the primary gemspec.

Returns:

  • (String)

    The gemspec name.



66
67
68
# File 'lib/rubygems/tasks/project.rb', line 66

def primary_gemspec
  @primary_gemspec
end

#rootString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The project directory.

Returns:

  • (String)

    The path to the project.



28
29
30
# File 'lib/rubygems/tasks/project.rb', line 28

def root
  @root
end

#scmSymbol? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The SCM the project is using.

Returns:

  • (Symbol, nil)

    The SCM the project is using.



42
43
44
# File 'lib/rubygems/tasks/project.rb', line 42

def scm
  @scm
end

Class Method Details

.directoriesHash{String => Project}

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Maps project directories to projects.

Returns:

  • (Hash{String => Project})

    Project directories and project objects.



130
131
132
133
134
# File 'lib/rubygems/tasks/project.rb', line 130

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

Instance Method Details

#bundler?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Specifies whether the project uses Bundler.

Returns:

  • (Boolean)


141
142
143
# File 'lib/rubygems/tasks/project.rb', line 141

def bundler?
  @bundler
end

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.



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

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

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

  return @gemspecs[name]
end