What object processes new Gem::Specification objects? - ruby

What object/process picks up a newly created Specification object when running gem build against a typical gemspec file?
For instance, suppose we have mynewgem.gemspec with contents as follows:
Gem::Specification.new do |s|
s.name = "mynewgem"
s.version = "0.0.1"
s.summary = "here is a summary"
s.description = "here is a desc"
s.authors = ["Full Name"]
s.email = "myname#mydomain.net"
s.files = Dir.glob("lib/**/*", File::FNM_DOTMATCH)
s.homepage = "https://rubygems.org/gems/mynewgem"
s.license = "My License"
s.add_dependency "this-dependency", "~> 1.2.3"
s.add_dependency "that-dependency", "~> 4.5.6"
end
What class/method is referencing the newly created Gem::Specification object here? It's obviously not directly assigned to a variable in mynewgem.gemspec. How does whatever sees this new object actually see/reference it?

What object/process picks up [the] newly created Specification object when running gem build against a typical gemspec file?
Please see Gem::Commands::BuildCommand#build_package
# rubygems/commands/build_command.rb
def build_package(gemspec)
spec = Gem::Specification.load(gemspec)
if spec
Gem::Package.build(
# etc ...

Related

gemspec is broken, cli won't run

I keep running into a problem, this gemspec is invalid. Can someone please help me?
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "Practical/version"
Gem::Specification.new do |spec|
spec.name = "Practical"
spec.version = Practical::VERSION
spec.authors = ["'D'"]
spec.email = ["'#gmail.com'"]
spec.summary = %q{TODO: Write a short summary, because
RubyGems requires one.}
spec.description = %q{TODO: Write a longer description or delete
this line.}
spec.homepage = "TODO: Put your gem's website or public repo
URL here."
spec.license = "MIT"
# Prevent pushing this gem to RubyGems.org. To allow pushes either
set the 'allowed_push_host'
# to allow pushing to a single host or delete this section to allow
pushing to any host.
if spec.respond_to?(:metadata)
spec.metadata["allowed_push_host"] = "TODO: Set to
'http://mygemserver.com'"
spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo
URL here."
spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md
URL here."
else
raise "RubyGems 2.0 or newer is required to protect against "
"public gem pushes."
end
# Specify which files should be added to the gem when it is
released.
# The `git ls-files -z` loads the files in the RubyGem that have
been added into git.
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
`git ls-files -z`.split("\x0").reject { |f|
f.match(%r{^(test|spec|features)/}) }
end
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f|
File.basename(f) }
spec.require_paths = ["lib"]
spec.add_development_dependency "bundler", "~> 1.17"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_dependency "nokogiri"`enter code here`
end
I'm not sure what changed. This worked a few months ago, but now it's broken. Basically, I'm stuck just getting this to run, the interpreter keeps telling me I have an error in my gemspec. I can't find it.

'rake native' fails with "undefined method split for nil:NilClass"

I'm creating a Ruby C extension for which I would like to create prepackaged binary packages, as the compilation requires a fair amount of dependencies. I'm new to Ruby, but it seems like gem doesn't want to create platform-specific packages, so the common way is to use the rake-compiler gem, and do rake native. I can get it to compile the extension, but then it fails with the error
NoMethodError: undefined method `split' for nil:NilClass
Running with --trace shows that the error is in rake-compiler-1.0.7/lib/rake/extensiontask.rb:515:
def ruby_api_version(ruby_version)
ruby_version.split(".")[0, 2].join(".")
end
This is because ruby_version is nil. It is called from rake-compiler-1.0.7/lib/rake/extensiontask.rb:262 in define_native_tasks():
ruby_versions = #ruby_versions_per_platform[platf] || []
sorted_ruby_versions = ruby_versions.sort_by do |ruby_version|
ruby_version.split(".").collect(&:to_i)
end
spec.required_ruby_version = [
">= #{ruby_api_version(sorted_ruby_versions.first)}",
"< #{ruby_api_version(sorted_ruby_versions.last).succ}.dev"
]
#ruby_versions_per_platform is set to {} in the constructor, but no line of code ever sets it. Thus, sorted_ruby_versions is empty, and .first and .last are nil, which results in the argument to ruby_api_version being nil.
Looking at git blame in the project shows that the these lines are 2 years old, and a result of the changeset https://github.com/rake-compiler/rake-compiler/commit/0dc23504cb03ed2fb3c506e1bb58af48d3851d1e. However, ruby_versions_per_platform is never assigned to outside the constructor, which means ruby_api_version will always get called with nil and will always fail. So how can this have worked for two years?
And more importantly, what do I have to do to get rake native to actually work?
I am using macOS 10.12.6, Ruby 2.3.7p456 installed with MacPorts (selected with port select --set ruby ruby26), rake-compiler 1.0.7, and rake-12.3.2.
Rakefile:
require "rake/extensiontask"
gemspec = Gem::Specification::load("mygem.gemspec")
Gem::PackageTask.new(gemspec) do |pkg|
end
Rake::ExtensionTask.new("mygem", gemspec) do |ext|
end
mygem.gemspec
Gem::Specification.new do |s|
s.name = "mygem"
s.version = "1.0.0rc1"
s.authors = [ "John Doe" ]
s.summary = "Awesome library"
s.description = "Awesome library because, reasons"
s.licenses = [ 'MIT' ]
s.email = "johndoe#null.com"
s.homepage = "http://www.null.com"
s.extensions = %w[ext/mygem/extconf.rb]
s.files = FileList['lib/**/*.rb', 'ext/**/*.{rb,c,h}']
s.platform = Gem::Platform::RUBY
s.required_ruby_version = '>= 1.8'
end
My project layout is
Rakefile
mygem.gemspec
ext/
mygem/
extconf.rb
mygem.c (generated with SWIG 3.0)
lib/
mygem.rb

Require in gem don't work

I created gem with bundler and puts all my ruby files into '/lib' as documentation suggested.
But I have a problem, after build the gem which "rake build" command and install (gem install pkg/gem) I can't use it because:
LoadError: cannot load such file -- mygem/client
this is cause because in main file i try to require 'mygem/client.rb' which is in lib/mygem/client.rb
and it is doesn't work :/
This is my gemspec:
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'diggy/version'
Gem::Specification.new do |spec|
spec.name = "diggy"
spec.version = Diggy::VERSION
spec.authors = [""]
spec.email = [""]
spec.summary = %q{: Write a short summary, because Rubygems requires one.}
spec.description = %q{: Write a longer description or delete this line.}
spec.homepage = ""
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
# to allow pushing to a single host or delete this section to allow pushing to any host.
if spec.respond_to?(:metadata)
spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
else
raise "RubyGems 2.0 or newer is required to protect against " \
"public gem pushes."
end
spec.files = `git ls-files -z`.split("\x0")
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.add_development_dependency "bundler", "~> 1.14"
spec.add_development_dependency "rake", "~> 10.0"
end
Assuming your main file is named mygem.rb and is inside the lib folder, you should be able to require the file lib/mygem/client.rb with:
require 'mygem/client'
Notice that I didn't use the .rb extension.

Rubygem creation ... I have pushed a new gem but the Source Code link is missing

I created and pushed a new gem for the first time in several years. I am a newbie in the Gem business.
I followed the various instructions and the gem was successfully pushed. Here is the link to new gem:
https://rubygems.org/gems/yequel
The only problem is that the 'Source Code' link does not appear on the above page. I have attached the gemspec that was used to push the gem.
Please help me identify what I am missing.
Thanks ... Al
#----------------------------------------------------------------------------
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'yequel/version'
Gem::Specification.new do |spec|
spec.name = "yequel"
spec.version = Yequel::VERSION
spec.authors = ["Al Kivi"]
spec.email = ["al.kivi#vizi.ca"]
spec.summary = %q{Provides a sequel style ORM layer for YAML::Store}
spec.description = %q{Yequel provides a sequel style with basic features to access YAML::Store tables. Its target audience is application developers who require light weight alternative to SQL databases.}
spec.homepage = "https://rubygems.org/profiles/vizi_master"
spec.license = "MIT"
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
# delete this section to allow pushing this gem to any host.
#if spec.respond_to?(:metadata)
#spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
#else
#raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
#end
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.add_development_dependency "bundler", "~> 1.11"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_runtime_dependency "hash_dot"
spec.add_runtime_dependency "will_paginate"
end
The Source link isn’t specified in the gemspec, only the homepage (which could point to a code repository).
If you want to set the the source link you need to do it on the Rubygems site. Sign into rubygems.org, and go to https://rubygems.org/gems/yequel/edit (there should be a link to this page from your gem’s page in the “Links” section, if you are signed in). From there you should be able to set the Source Code URL, along with a range of other URLs.

requiring a custom gem

I forked https://github.com/evolve75/RubyTree and made a few changes for usage in an application. I also added a rubytree.gemspec (which was not present in the original repo) in order to install it with bundler using a Gemfile in my application:
gem 'rubytree', :git => 'git#github.com:anthonylebrun/RubyTree.git'
I do a bundle install in my app and everything goes smoothly but I'm not able to
require 'rubygems'
require 'tree'
and just have it work. Instead I get:
LoadError: no such file to load -- tree
So I suspect I may be setting up paths wrong? I'm no gemspec pro, I just threw it together by looking at another gem. Here it is:
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = 'rubytree'
s.version = '0.8.1'
s.summary = 'Tree data structure'
s.description = 'RubyTree allows you to create and manipulate tree structures in ruby'
s.required_ruby_version = '>= 1.8.7'
s.required_rubygems_version = ">= 1.3.6"
s.author = 'Anupam Sengupta'
s.email = 'anupamsg#gmail.com'
s.homepage = 'http://rubytree.rubyforge.org/'
s.files = ['lib/tree.rb']
s.require_path = ['lib']
end
Any ideas? If there's anything I can clarify, let me know too!
Have you tried this?
require 'rubygems'
require 'bundler/setup'
require 'tree'
Have you tried
require 'rubytree'
as well?

Resources