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'.freeze
BUILD_TO_DIRNAME =
'pkg'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_path) ⇒ Gemspec

Returns a new instance of Gemspec.

Raises:

  • (NotFoundError)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ggem/gemspec.rb', line 15

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.



13
14
15
# File 'lib/ggem/gemspec.rb', line 13

def gem_file
  @gem_file
end

#gem_file_nameObject (readonly)

Returns the value of attribute gem_file_name.



13
14
15
# File 'lib/ggem/gemspec.rb', line 13

def gem_file_name
  @gem_file_name
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/ggem/gemspec.rb', line 12

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



12
13
14
# File 'lib/ggem/gemspec.rb', line 12

def path
  @path
end

#push_hostObject (readonly)

Returns the value of attribute push_host.



13
14
15
# File 'lib/ggem/gemspec.rb', line 13

def push_host
  @push_host
end

#versionObject (readonly)

Returns the value of attribute version.



12
13
14
# File 'lib/ggem/gemspec.rb', line 12

def version
  @version
end

#version_tagObject (readonly)

Returns the value of attribute version_tag.



12
13
14
# File 'lib/ggem/gemspec.rb', line 12

def version_tag
  @version_tag
end

Instance Method Details

#run_build_cmdObject



33
34
35
36
37
38
39
# File 'lib/ggem/gemspec.rb', line 33

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



41
42
43
# File 'lib/ggem/gemspec.rb', line 41

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

#run_push_cmdObject



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

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