📜 ⬆️ ⬇️

Meet the Gem. Part two

Good day!

Instead of introducing


I finally found some time to continue my narration about the various wonders of Ruby. As you remember, in the last part we learned the basics of writing your heme. We learned what the minimum set of files should be in order to collect it. We also learned how we can publish our creation in RubyGems. On the same day (after writing the first part), a splash of gems called hello-world suddenly appeared in RubyGems. And I found quite a lot of variations thereof. Some did not even bother to change the line where the author of the heme is indicated.
g.author = "krovatti" 

Some even asked the gem the following version values:
 g.version = "666" g.version = "111" g.version = "911" 

In general, there were quite a few other variations, which, of course, I, as an author, could not but rejoice.


What awaits us today


In today's part, I would like to provide you with an overview of the properties available to us in the specification file. Knowledge of these very properties is, in my opinion, MUST HAVE .
Since we are already able to build gems, let us move on to the theory itself.
')

Where do we start


I think the beginning of the listing is as follows:

So, let's begin.

date

Type: Time.
Default value: Time.now
Description: The date / time the gem was created.
Example:
 g.date = File.utime('VERSION') 

Note: usually this field is not filled by programmers, because it already has a default value.

name

Type: String.
Default value: no.
Description: The name of our gem.
Example:
 g.name = 'woohaha' 

Note: in the name you can not write the version number of our gem, because for this there is a separate field.

platform

Type: String.
Default value: Gem :: Platform :: Ruby
Description: The platform for which, in fact, we wrote our heme.
Example:
 g.platform = Gem::Platform::Win32 

Note: this property should be filled only if your geme has an extension intended only for a specific platform. For example, we wrote Win API wrapper.

require_paths

Type: Array.
Default value: ["lib"]
Description: A listing that indicates the mandatory presence of a folder with our .rb or README files.
Example:
 #        g.require_paths = '.' # , ,     'lib  'ext' g.require_paths << 'ext' 

Note: this property should not be used only in the case of HelloWorlds, in the rest, of course, it’s worth it, because sometimes it is still convenient to locate horses in their stables, and not to keep everyone in one.

summary

Type: String.
Default value: no.
Description: a brief description of our heme.
Example:
 g.summary = 'I love Ruby and this extension was created specially for its beauty' 

Note: this property is often confused with the description property, which is a less important property.

And the last required property for today. and for life

version

Type: String.
Default value: no.
Description: our gem version.
Example:
 g.version = '1.0.5' 

Note: Values ​​represented by the Gem :: Version class can also be a valid value, but basically no one uses it. Remember that the string should contain only numeric values, not text.

That's all. We have dealt with the required properties. Now, you can safely substitute your names, version numbers, etc., and not publish them under my name. Just kidding, I certainly don't mind.
Are you tired? Strong? You can drink a cup of coffee, then return to us at the light.

So let's continue


In addition to the required properties that you must apply, you should not forget about optional. Well, let's get started.

author or authors

Type: String or Array, in case there are several authors.
Default value: no.
Description: indicates the name or nickname of the author of the gem, or the creator of the library's Universe contained in the geme.
Example:
 #    g.author = 'Mike Vazovski' #     g.authors = ['Mike Vazovski', 'Vladimir Putin'] 

Note: no comments.

autorequire

No, we will not be distracted by it, because it was long ago banned as unnecessary. And go ahead.

bindir

Type: String.
Default value: "bin"
Description: A folder containing files of any executable file, i.e. applications, if any.
Example:
 g.bindir = 'bin' 

Note: under the “application” any file that can be executed via the command line is indicated.

default_executable

Type: String.
Default value: no . It has . As in the column "marital status" everything is difficult . Not really. Read the note.
Description: A folder containing an application that can be launched from gem.
Example:
 g.default_executable = 'bin/debin' 

Note: if only one directory is specified in executables , then it will be the value for default_executable . This value is worth touching if you have two or more executable files.

dependencies

Type: Array.
The default value is [], i.e. nothing is required.
Description: Listing of gems necessary for our work.
Example:
 g.add_dependencies 'sinatra' 

Note: the storage in which already installed gems live will be checked first. If we need to be found, then nothing terrible will happen, nor will it find it. In this case, the missing gems will be downloaded from the RubyGems repository.

development_dependencies

A property similar to the previous one.

description

In fact, this property is not recommended to use. Instead, use summary

email

Type: String or Array.
Default value: no.
Description: e-mail for feedback with the author / authors.
Example:
 #    g.email = 'krovatti@gmail.com' #    g.email = ['blablabla@yahoo.eu','krovatti@gmail.com'] 

Note: this was also a hint for read-only accounts, which, in the case of circumstances, often simply cannot contact the author of the topic for any questions of interest.

executables

We already spoke about this property in default_executable . There is nothing more to say about him.

extensions

Type: Array.
Default value: no.
Description: Directories containing extension files.
Example:
 g.extensions << 'ext/rmagic/wtf.rb' 

Note: these files will be run when the gem is installed and extensions are compiled.

extra_rdoc_files

Type: Array.
Default value: no.
Description: Lists additional files that will be used when generating RDoc documentation.
Example:
 g.extra_rdoc_files = ['README', 'doc/user-guide.txt'] 

Note: no comments.

files

Type: Array.
Default value: no.
Description: Listing of files contained in geme.
Example:
 g.files = Dir['lib/**/*.rb] 

Note: there is also nothing special to comment on.

has_rdoc

Type: Boolean.
Default value: false
Description: Indicates if there is documentation for this RDoc gem.
Example:
 g.has_rdoc = true 

Note: a property that devours a certain number of bytes in your file.

homepage

Type: String.
Default value: microsoft.com, yeah, it doesn't.
Description: the address of the site of this gem.
Example:
 g.homepage = 'http://github.com/ln/xmpp4r' 

Note: also no comments.

license or licenses

Type: String or Array.
Default value: no.
Description: license / licenses under which gems were published.
Example:
 g.license = 'MIT' #    g.licenses = ['MIT', 'GPL-2'] #   ,  

Note: each license name must be no more than 64 characters.

rdoc_options

Type: Array.
Default value: []
Description: Specifies the formatting of the RDoc documentation.
Example:
 g.rdoc_options << '--title' << 'Rake -- Ruby Make' << '--main' << 'README' << --line-numbers' 

Note: try and make sure it works.

required_ruby_version

Type: Gem :: Version :: Requirement.
Default value: > 0.0.0
Description: The Ruby version required for working with our gem.
Example:
 g.required_ruby_version = '>= 1.8.1' 

Note: A very useful feature that will lead to fewer errors when trying to use heme. Take the situation with the same XMPP4R, which does not work with 1.9.0 or wind up on the mood.

requirements

We will not consider this property as unnecessary, because it carries only textual information for the user.

rubyforge_project

Type: String.
Default value: no.
Description: The name of the project at RubyForge.
Example:
 g.rubyforge_project = 'yahoo-eu' 

Note: if you do not have a project on RubyForge, do not touch this property as useless.

And, about a miracle (!!!) last property.

test_files

Type: String or Array.
Default value: '' or []
Description: The directory / directories whose contents are your unit tests, if any.
Example:
 g.test_files = 'tests/wtf.rb' # 1 g.test_files = ['tests/wtf.rb',tests/wtf2.rb'] 


That's all


On this the second part of our acquaintance with the gem is over. Today we have learned about all sorts of properties used to correctly configure the heme. I would like to congratulate those who have reached the end of this topic with healthy eyes. But, alas, boobs will not be!

See you soon!

Oh yeah, I almost forgot. You can also be guided by this guide when fixing the study.

Source: https://habr.com/ru/post/134878/


All Articles