Class: GGem::Gemspec

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

Constant Summary collapse

PUSH_HOST_META_KEY =
"allowed_push_host"
DEFAULT_PUSH_HOST =
"https://rubygems.org"
BUILD_TO_DIRNAME =
"pkg"
NotFoundError =
Class.new(ArgumentError)
LoadError =
Class.new(ArgumentError)
CmdError =
Class.new(RuntimeError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_path) ⇒ Gemspec

Returns a new instance of Gemspec.

Raises:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ggem/gemspec.rb', line 20

def initialize(root_path)
  @root = Pathname.new(File.expand_path(root_path))
  raise NotFoundError unless @root.exist?
  @path = Pathname.new(Dir[File.join(@root, "{,*}.gemspec")].first.to_s)
  raise NotFoundError unless @path.exist?

  @spec        = load_gemspec(@path)
  @name        = @spec.name
  @version     = @spec.version
  @version_tag = "v#{@version}"

  @gem_file_name  = "#{@name}-#{@version}.gem"
  @gem_file       = File.join(BUILD_TO_DIRNAME, @gem_file_name)
  @built_gem_path = @root.join(@gem_file)

  @push_host = get_push_host(@spec)
end

Instance Attribute Details

#gem_fileObject (readonly)

Returns the value of attribute gem_file.



18
19
20
# File 'lib/ggem/gemspec.rb', line 18

def gem_file
  @gem_file
end

#gem_file_nameObject (readonly)

Returns the value of attribute gem_file_name.



18
19
20
# File 'lib/ggem/gemspec.rb', line 18

def gem_file_name
  @gem_file_name
end

#nameObject (readonly)

Returns the value of attribute name.



17
18
19
# File 'lib/ggem/gemspec.rb', line 17

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



17
18
19
# File 'lib/ggem/gemspec.rb', line 17

def path
  @path
end

#push_hostObject (readonly)

Returns the value of attribute push_host.



18
19
20
# File 'lib/ggem/gemspec.rb', line 18

def push_host
  @push_host
end

#versionObject (readonly)

Returns the value of attribute version.



17
18
19
# File 'lib/ggem/gemspec.rb', line 17

def version
  @version
end

#version_tagObject (readonly)

Returns the value of attribute version_tag.



17
18
19
# File 'lib/ggem/gemspec.rb', line 17

def version_tag
  @version_tag
end

Instance Method Details

#run_build_cmdObject



38
39
40
41
42
43
44
# File 'lib/ggem/gemspec.rb', line 38

def run_build_cmd
  run_cmd("gem build --verbose #{@path}").tap do
    gem_path = @root.join(@gem_file_name)
    run_cmd("mkdir -p #{@built_gem_path.dirname}")
    run_cmd("mv #{gem_path} #{@built_gem_path}")
  end
end

#run_install_cmdObject



46
47
48
# File 'lib/ggem/gemspec.rb', line 46

def run_install_cmd
  run_cmd("gem install #{@built_gem_path}")
end

#run_push_cmdObject



50
51
52
# File 'lib/ggem/gemspec.rb', line 50

def run_push_cmd
  run_cmd("gem push #{@built_gem_path} --host #{@push_host}")
end