Project
Reverse Dependencies for lookout
The projects listed here declare lookout as a runtime or development dependency
0.0
Ame
Ame provides a simple command-line interface API for Ruby¹. It can be used
to provide both simple interfaces like that of ‹rm›² and complex ones like
that of ‹git›³. It uses Ruby’s own classes, methods, and argument lists to
provide an interface that is both simple to use from the command-line side
and from the Ruby side. The provided command-line interface is flexible and
follows commond standards for command-line processing.
¹ See http://ruby-lang.org/
² See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/rm.html
³ See http://git-scm.com/docs/
§ Usage
Let’s begin by looking at two examples, one where we mimic the POSIX¹
command-line interface to the ‹rm› command. Looking at the entry² in the
standard, ‹rm› takes the following options:
= -f. = Do not prompt for confirmation.
= -i. = Prompt for confirmation.
= -R. = Remove file hierarchies.
= -r. = Equivalent to /-r/.
It also takes the following arguments:
= FILE. = A pathname or directory entry to be removed.
And actually allows one or more of these /FILE/ arguments to be given.
We also note that the ‹rm› command is described as a command to “remove
directory entries”.
¹ See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/contents.html
² See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/rm.html
Let’s turn this specification into one using Ame’s API. We begin by adding
a flag for each of the options listed above:
class Rm < Ame::Root
flag 'f', '', false, 'Do not prompt for confirmation'
flag 'i', '', nil, 'Prompt for confirmation' do |options|
options['f'] = false
end
flag 'R', '', false, 'Remove file hierarchies'
flag 'r', '', nil, 'Equivalent to -R' do |options|
options['r'] = true
end
A flag¹ is a boolean option that doesn’t take an argument. Each flag gets
a short and long name, where an empty name means that there’s no
corresponding short or long name for the flag, a default value (true,
false, or nil), and a description of what the flag does. Each flag can
also optionally take a block that can do further processing. In this case
we use this block to modify the Hash that maps option names to their values
passed to the block to set other flags’ values than the ones that the block
is associated with. As these flags (‘i’ and ‘r’) aren’t themselves of
interest, their default values have been set to nil, which means that they
won’t be included in the Hash that maps option names to their values when
passed to the method.
¹ See http://disu.se/software/ame-1.0/api/user/Ame/Class#flag-class-method
There are quite a few other kinds of options besides flags that can be
defined using Ame, but flags are all that are required for this example.
We’ll get to the other kinds in later examples.
Next we add a “splus” argument.
splus 'FILE', String, 'File to remove'
A splus¹ argument is like a Ruby “splat”, that is, an Array argument at the
end of the argument list to a method preceded by a star, except that a
splus requires at least one argument. A splus argument gets a name for the
argument (‹FILE›), the type of argument it represents (String), and a
description.
¹ See http://disu.se/software/ame-1.0/api/user/Ame/Class#splus-class-method
Then we add a description of the command (method) itself:
description 'Remove directory entries'
Descriptions¹ will be used in help output to assist the user in using the
command.
¹ See http://disu.se/software/ame-1.0/api/user/Ame/Class#description-class-method
Finally, we add the Ruby method that’ll implement the command (all
preceding code included here for completeness):
class Rm < Ame::Root
version '1.0.0'
flag 'f', '', false, 'Do not prompt for confirmation'
flag 'i', '', nil, 'Prompt for confirmation' do |options|
options['f'] = false
end
flag 'R', '', false, 'Remove file hierarchies'
flag 'r', '', nil, 'Equivalent to -R' do |options|
options['r'] = true
end
splus 'FILE', String, 'File to remove'
description 'Remove directory entries'
def rm(files, options = {})
require 'fileutils'
FileUtils.send options['R'] ? :rm_r : :rm,
[first] + rest, :force => options['f']
end
end
Actually, another bit of code was also added, namely
version '1.0.0'
This sets the version¹ String of the command. This information is used
when the command is invoked with the “‹--version›” flag. This flag is
automatically added, so you don’t need to add it yourself. Another flag,
“‹--help›”, is also added automatically. When given, this flag’ll make Ame
output usage information of the command.
¹ See http://disu.se/software/ame-1.0/api/user/Ame/Class#version-class-method
To actually run the command, all you need to do is invoke
Rm.process
This’ll invoke the command using the command-line arguments stored in
‹ARGV›, but you can also specify other ones if you want to:
Rm.process 'rm', %w[-r /tmp/*]
The first argument to #process¹ is the name of the method to invoke, which
defaults to ‹File.basename($0)›, and the second argument is an Array of
Strings that should be processed as command-line arguments passed to the
command.
¹ See http://disu.se/software/ame-1.0/api/user/Ame/Class#process-class-method
If you’d store the complete ‹Rm› class defined above in a file called ‹rm›
and add ‹#! /usr/bin/ruby -w› at the beginning and ‹Rm.process› at the end,
you’d have a fully functional ‹rm› command (after making it executable).
Let’s see it in action:
% rm --help
Usage: rm [OPTIONS]... FILE...
Remove directory entries
Arguments:
FILE... File to remove
Options:
-R Remove file hierarchies
-f Do not prompt for confirmation
--help Display help for this method
-i Prompt for confirmation
-r Equivalent to -R
--version Display version information
% rm --version
rm 1.0.0
Some commands are more complex than ‹rm›. For example, ‹git›¹ has a rather
complex command-line interface. We won’t mimic it all here, but let’s
introduce the rest of the Ame API using a fake ‹git› clone as an example.
¹ See http://git-scm.com/docs/
‹Git› uses sub-commands to achieve most things. Implementing sub-commands
with Ame is done using a “dispatch”. We’ll discuss dispatches in more
detail later, but suffice it to say that a dispatch delegates processing to
a child class that’ll handle the sub-command in question. We begin by
defining our main ‹git› command using a class called ‹Git› under the
‹Git::CLI› namespace:
module Git end
class Git::CLI < Ame::Root
version '1.0.0'
class Git < Ame::Class
description 'The stupid content tracker'
def initialize; end
We’re setting things up to use the ‹Git› class as a dispatch in the
‹Git::CLI› class. The description on the ‹initialize› method will be used
as a description of the ‹git› dispatch command itself.
Next, let’s add the ‹format-patch›¹ sub-command:
description 'Prepare patches for e-mail submission'
flag ?n, 'numbered', false, 'Name output in [PATCH n/m] format'
flag ?N, 'no-numbered', nil,
'Name output in [PATCH] format' do |options|
options['numbered'] = false
end
toggle ?s, 'signoff', false,
'Add Signed-off-by: line to the commit message'
switch '', 'thread', 'STYLE', nil,
Ame::Types::Enumeration[:shallow, :deep],
'Controls addition of In-Reply-To and References headers'
flag '', 'no-thread', nil,
'Disables addition of In-Reply-To and Reference headers' do |options, _|
options.delete 'thread'
end
option '', 'start-number', 'N', 1,
'Start numbering the patches at N instead of 1'
multioption '', 'to', 'ADDRESS', String,
'Add a To: header to the email headers'
optional 'SINCE', 'N/A', 'Generate patches for commits after SINCE'
def format_patch(since = '', options = {})
p since, options
end
¹ See http://git-scm.com/docs/git-format-patch/
We’re using quite a few new Ame commands here. Let’s look at each in turn:
toggle ?s, 'signoff', false,
'Add Signed-off-by: line to the commit message'
A “toggle”¹ is a flag that also has an inverse. Beyond the flags ‘s’ and
“signoff”, the toggle also defines “no-signoff”, which will set “signoff”
to false. This is useful if you want to support configuration files that
set “signoff”’s default to true, but still allow it to be overridden on the
command line.
¹ See http://disu.se/software/ame-1.0/api/user/Ame/Class#toggle-class-method
When using the short form of a toggle (and flag and switch), multiple ones
may be juxtaposed after the initial one. For example, “‹-sn›” is
equivalent to “‹-s -n›” to “git format-patch›”.
switch '', 'thread', 'STYLE', nil,
Ame::Types::Enumeration[:shallow, :deep],
'Controls addition of In-Reply-To and References headers'
A “switch”¹ is an option that takes an optional argument. This allows you
to have separate defaults for when the switch isn’t present on the command
line and for when it’s given without an argument. The third argument to a
switch is the name of the argument. We’re also introducing a new concept
here in ‹Ame::Types::Enumeration›. An enumeration² allows you to limit the
allowed input to a set of Symbols. An enumeration also has a default value
in the first item to its constructor (which is aliased as ‹.[]›). In this
case, the “thread” switch defaults to nil, but, when given, will default to
‹:shallow› if no argument is given. If an argument is given it must be
either “shallow” or “deep”. A switch isn’t required to take an enumeration
as its argument default and can take any kind of default value for its
argument that Ame knows how to handle. We’ll look at this in more detail
later, but know that the type of the default value will be used to inform
Ame how to parse a command-line argument into a Ruby value.
An argument to a switch must be given, in this case, as “‹--thread=deep›”
on the command line.
¹ See http://disu.se/software/ame-1.0/api/user/Ame/Class#switch-class-method
² See http://disu.se/software/ame-1.0/api/user/Ame/Types/Enumeration/
option '', 'start-number', 'N', 1,
'Start numbering the patches at N instead of 1'
An “option”¹ is an option that takes an argument. The argument must always
be present and may be given, in this case, as “‹--start-number=2›” or
“‹--start-number 2›” on the command line. For a short-form option,
anything that follows the option is seen as an argument, so assuming that
“start-number” also had a short name of ‘S’, “‹-S2›” would be equivalent to
“‹-S 2›”, which would be equivalent to “‹--start-number 2›”. Note that
“‹-snS2›” would still work as expected.
¹ See http://disu.se/software/ame-1.0/api/user/Ame/Class#option-class-method
multioption '', 'to', 'ADDRESS', String,
'Add a To: header to the email headers'
A “multioption”¹ is an option that takes an argument and may be repeated
any number of times. Each argument will be added to an Array stored in the
Hash that maps option names to their values. Instead of taking a default
argument, it takes a type for the argument (String, in this case). Again,
types are used to inform Ame how to parse command-line arguments into Ruby
values.
¹ See http://disu.se/software/ame-1.0/api/user/Ame/Class#multioption-class-method
optional 'SINCE', 'N/A', 'Generate patches for commits after SINCE'
An “optional”¹ argument is an argument that isn’t required. If it’s not
present on the command line it’ll get its default value (the String
‹'N/A'›, in this case).
¹ See http://disu.se/software/ame-1.0/api/user/Ame/Class#optional-class-method
We’ve now covered all kinds of options and one new kind of argument. There
are three more types of argument (one that we’ve already seen and two new)
that we’ll look into now: “argument”, “splat”, and “splus”.
description 'Annotate file lines with commit information'
argument 'FILE', String, 'File to annotate'
def annotate(file)
p file
end
An “argument”¹ is an argument that’s required. If it’s not present on the
command line, an error will be raised (and by default reported to the
terminal). As it’s required, it doesn’t take a default, but rather a type.
¹ See http://disu.se/software/ame-1.0/api/user/Ame/Class#argument-class-method
description 'Add file contents to the index'
splat 'PATHSPEC', String, 'Files to add content from'
def add(paths)
p paths
end
A “splat”¹ is an argument that’s not required, but may be given any number
of times. The type of a splat is the type of one argument and the type of
a splat as a whole is an Array of values of that type.
¹ See http://disu.se/software/ame-1.0/api/user/Ame/Class#splat-class-method
description 'Display gitattributes information'
splus 'PATHNAME', String, 'Files to list attributes of'
def check_attr(paths)
p paths
end
A “splus”¹ is an argument that’s required, but may also be given any number
of times. The type of a splus is the type of one argument and the type of
a splus as a whole is an Array of values of that type.
¹ See http://disu.se/software/ame-1.0/api/user/Ame/Class#splus-class-method
Now that we’ve seen all kinds of options and arguments, let’s look on an
additional tool at our disposal, the dispatch¹.
class Remote < Ame::Class
description 'Manage set of remote repositories'
def initialize; end
description 'Shows a list of existing remotes'
flag 'v', 'verbose', false, 'Show remote URL after name'
def list(options = {})
p options
end
description 'Adds a remote named NAME for the repository at URL'
argument 'name', String, 'Name of the remote to add'
argument 'url', String, 'URL to the repository of the remote to add'
def add(name, url)
p name, url
end
end
¹ See http://disu.se/software/ame-1.0/api/user/Ame/Class#dispatch-class-method
Here we’re defining a child class to Git::CLI::Git called “Remote” that
doesn’t introduce anything new. Then we set up the dispatch:
dispatch Remote, :default => 'list'
This adds a method called “remote” to Git::CLI::Git that will dispatch
processing of the command line to an instance of the Remote class when
“‹git remote›” is seen on the command line. The “remote” method expects an
argument that’ll be used to decide what sub-command to execute. Here we’ve
specified that in the absence of such an argument, the “list” method should
be invoked.
We add the same kind of dispatch to Git under Git::CLI:
dispatch Git
and then we’re done. Here’s all the previous code in its entirety:
module Git end
class Git::CLI < Ame::Root
version '1.0.0'
class Git < Ame::Class
description 'The stupid content tracker'
def initialize; end
description 'Prepare patches for e-mail submission'
flag ?n, 'numbered', false, 'Name output in [PATCH n/m] format'
flag ?N, 'no-numbered', nil,
'Name output in [PATCH] format' do |options|
options['numbered'] = false
end
toggle ?s, 'signoff', false,
'Add Signed-off-by: line to the commit message'
switch '', 'thread', 'STYLE', nil,
Ame::Types::Enumeration[:shallow, :deep],
'Controls addition of In-Reply-To and References headers'
flag '', 'no-thread', nil,
'Disables addition of In-Reply-To and Reference headers' do |options, _|
options.delete 'thread'
end
option '', 'start-number', 'N', 1,
'Start numbering the patches at N instead of 1'
multioption '', 'to', 'ADDRESS', String,
'Add a To: header to the email headers'
optional 'SINCE', 'N/A', 'Generate patches for commits after SINCE'
def format_patch(since = '', options = {})
p since, options
end
description 'Annotate file lines with commit information'
argument 'FILE', String, 'File to annotate'
def annotate(file)
p file
end
description 'Add file contents to the index'
splat 'PATHSPEC', String, 'Files to add content from'
def add(paths)
p paths
end
description 'Display gitattributes information'
splus 'PATHNAME', String, 'Files to list attributes of'
def check_attr(paths)
p paths
end
class Remote < Ame::Class
description 'Manage set of remote repositories'
def initialize; end
description 'Shows a list of existing remotes'
flag 'v', 'verbose', false, 'Show remote URL after name'
def list(options = {})
p options
end
description 'Adds a remote named NAME for the repository at URL'
argument 'name', String, 'Name of the remote to add'
argument 'url', String, 'URL to the repository of the remote to add'
def add(name, url)
p name, url
end
end
dispatch Remote, :default => 'list'
end
dispatch Git
end
If we put this code in a file called “git” and add ‹#! /usr/bin/ruby -w› at
the beginning and ‹Git::CLI.process› at the end, you’ll have a very
incomplete git command-line interface on your hands. Let’s look at what
some of its ‹--help› output looks like:
% git --help
Usage: git [OPTIONS]... METHOD [ARGUMENTS]...
The stupid content tracker
Arguments:
METHOD Method to run
[ARGUMENTS]... Arguments to pass to METHOD
Options:
--help Display help for this method
--version Display version information
Methods:
add Add file contents to the index
annotate Annotate file lines with commit information
check-attr Display gitattributes information
format-patch Prepare patches for e-mail submission
remote Manage set of remote repositories
% git format-patch --help
Usage: git format-patch [OPTIONS]... [SINCE]
Prepare patches for e-mail submission
Arguments:
[SINCE=N/A] Generate patches for commits after SINCE
Options:
-N, --no-numbered Name output in [PATCH] format
--help Display help for this method
-n, --numbered Name output in [PATCH n/m] format
--no-thread Disables addition of In-Reply-To and Reference headers
-s, --signoff Add Signed-off-by: line to the commit message
--start-number=N Start numbering the patches at N instead of 1
--thread[=STYLE] Controls addition of In-Reply-To and References headers
--to=ADDRESS* Add a To: header to the email headers
% git remote --help
Usage: git remote [OPTIONS]... [METHOD] [ARGUMENTS]...
Manage set of remote repositories
Arguments:
[METHOD=list] Method to run
[ARGUMENTS]... Arguments to pass to METHOD
Options:
--help Display help for this method
Methods:
add Adds a remote named NAME for the repository at URL
list Shows a list of existing remotes
§ API
The previous section gave an introduction to the whole user API in an
informal and introductory way. For an indepth reference to the user API,
see the {user API documentation}¹.
¹ See http://disu.se/software/ame-1.0/api/user/Ame/
If you want to extend the API or use it in some way other than as a
command-line-interface writer, see the {developer API documentation}¹.
¹ See http://disu.se/software/ame-1.0/api/developer/Ame/
§ Financing
Currently, most of my time is spent at my day job and in my rather busy
private life. Please motivate me to spend time on this piece of software
by donating some of your money to this project. Yeah, I realize that
requesting money to develop software is a bit, well, capitalistic of me.
But please realize that I live in a capitalistic society and I need money
to have other people give me the things that I need to continue living
under the rules of said society. So, if you feel that this piece of
software has helped you out enough to warrant a reward, please PayPal a
donation to now@disu.se¹. Thanks! Your support won’t go unnoticed!
¹ Send a donation:
https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=now@disu.se&item_name=Ame
§ Reporting Bugs
Please report any bugs that you encounter to the {issue tracker}¹.
¹ See https://github.com/now/ame/issues
§ Authors
Nikolai Weibull wrote the code, the tests, the documentation, and this
README.
§ Licensing
Ame is free software: you may redistribute it and/or modify it under the
terms of the {GNU Lesser General Public License, version 3}¹ or later², as
published by the {Free Software Foundation}³.
¹ See http://disu.se/licenses/lgpl-3.0/
² See http://gnu.org/licenses/
³ See http://fsf.org/
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
Activity
0.0
# COM #
COM is an object-oriented wrapper around WIN32OLE. COM makes it easy to add
behavior to WIN32OLE objects, making them easier to work with from Ruby.
## Usage ##
Using COM is rather straightforward. There’s basically four concepts to keep
track of:
1. COM objects
2. Instantiable COM objects
3. COM events
4. COM errors
Let’s look at each concept separately, using the following example as a base.
module Word end
class Word::Application < COM::Instantiable
def without_interaction
with_properties('displayalerts' => Word::WdAlertsNone){ yield }
end
def documents
Word::Documents.new(com.documents)
end
def quit(saving = Word::WdDoNotSaveChanges, *args)
com.quit saving, *args
end
end
### COM Objects ###
A COM::Object is a wrapper around a COM object. It provides error
specialization, which is discussed later and a few utility methods. You
typically use it to wrap COM objects that are returned by COM methods. If we
take the example given in the introduction, Word::Documents is a good
candidate:
class Word::Documents < COM::Object
DefaultOpenOptions = {
'confirmconversions' => false,
'readonly' => true,
'addtorecentfiles' => false,
'visible' => false
}.freeze
def open(path, options = {})
options = DefaultOpenOptions.merge(options)
options['filename'] = Pathname(path).to_com
Word::Document.new(com.open(options))
end
end
Here we override the #open method to be a bit easier to use, providing sane
defaults for COM interaction. Worth noting is the use of the #com method to
access the actual COM object to invoke the #open method on it. Also note that
Word::Document is also a COM::Object.
COM::Object provides a convenience method called #with_properties, which is
used in the #without_interaction method above. It lets you set properties on
the COM::Object during the duration of a block, restoring them after it exits
(successfully or with an error).
### Instantiable COM Objects ###
Instantiable COM objects are COM objects that we can connect to and that can be
created. The Word::Application object can, for example, be created.
Instantiable COM objects should inherit from COM::Instantiable. Instantiable
COM objects can be told what program ID to use, whether or not to allow
connecting to an already running object, and to load its associated constants
upon creation.
The program ID is used to determine what instantiable COM object to connect to.
By default the name of the COM::Instantiable class’ name is used, taking the
last two double-colon-separated components and joining them with a dot. For
Word::Application, the program ID is “Word.Application”. The program ID can be
set by using the .program_id method:
class IDontCare::ForConventions < COM::Instantiable
program_id 'Word.Application'
end
The program ID can be accessed with the same method:
Word::Application.program_id # ⇒ 'Word.Application'
Connecting to an already running COM object is not done by default, but is
sometimes desirable: the COM object might take a long time to create, or some
common state needs to be accessed. If the default for a certain instantiable
COM object should be to connect, this can be done using the .connect method:
class Word::Application < COM::Instantiable
connect
end
If no running COM object is available, then a new COM object will be created in
its stead. Whether or not a class uses the connection method can be queried
with the .connect? method:
Word::Application.connect? # ⇒ true
Whether or not to load constants associated with an instantiable COM object is
set with the .constants method:
class Word::Application < COM::Instantiable
constants true
end
and can similarly be checked:
Word::Application.constants? # ⇒ true
Constants are loaded by default.
When an instance of the instantiable COM object is created, a check is run to
see if constants should be loaded and whether or not they already have been
loaded. If they should be loaded and they haven’t already been loaded,
they’re, you guessed it, loaded. The constants are added to the module
containing the COM::Instantiable. Thus, for Word::Application, the Word module
will contain all the constants. Whether or not the constants have already been
loaded can be checked with .constants_loaded?:
Word::Application.constants_loaded # ⇒ false
That concludes the class-level methods.
Let’s begin with the #connected? method among the instance-level methods. This
method queries whether or not this instance connected to an already running COM
object:
Word::Application.new.connected? # ⇒ false
This can be very important in determining how shutdown of a COM object should
be done. If you connected to an already COM object it might be foolish to shut
it down if someone else is using it.
The #initialize method takes a couple of options:
* connect: whether or not to connect to a running instance
* constants: whether or not to load constants
These options will, when given, override the class-level defaults.
### Events ###
COM events are easily dealt with:
class Word::Application < COM::Instantiable
def initialize(options = {})
super
@events = COM::Events.new(com, 'ApplicationEvents',
'OnQuit')
end
def quit(saving = Word::WdDoNotSaveChanges, *args)
@events.observe('OnQuit', proc{ com.quit saving, *args }) do
yield if block_given?
end
end
end
To tell you the truth this API sucks and will most likely be rewritten. The
reason that it is the way it is is that WIN32OLE, which COM wraps, sucks. It’s
event API is horrid and the implementation is buggy. It will keep every
registered event block in memory for ever, freeing neither the blocks nor the
COM objects that yield the events.
### Errors ###
All errors generated by COM methods descend from COM::Error, except for those
cases where a Ruby error already exists. The following HRESULT error codes are
turned into Ruby errors:
HRESULT Error Code | Error Class
-------------------|------------
0x80004001 | NotImplementedError
0x80020005 | TypeError
0x80020006 | NoMethodError
0x8002000e | ArgumentError
0x800401e4 | ArgumentError
There are also a couple of other HRESULT error codes that are turned into more
specific errors than COM::Error:
HRESULT Error Code | Error Class
-------------------|------------
0x80020003 | MemberNotFoundError
0x800401e3 | OperationUnavailableError
Finally, when a method results in any other error, a COM::MethodInvocationError
will be raised, which can be queried for the specifics, specifically #message,
#method, #server, #code, #hresult_code, and #hresult_message.
### Pathname ###
The Pathname object receives an additional method, #to_com. This method is
useful for when you want to pass a Pathname object to a COM method. Simply
call #to_com to turn it into a String of the right encoding for COM:
Word::Application.new.documents.open(Pathname('a.docx').to_com)
# ⇒ Word::Document
## Installation ##
Install COM with
% gem install com
## License ##
You may use, copy and redistribute this library under the same [terms][1] as
Ruby itself.
[1]: http://www.ruby-lang.org/en/LICENSE.txt
## Contributors ##
* Nikolai Weibull
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
0.0
Inventory
Inventory keeps track of the contents of your Ruby¹ projects. Such an
inventory can be used to load the project, create gem specifications and
gems, run unit tests, compile extensions, and verify that the project’s
content is what you think it is.
¹ See http://ruby-lang.org/
§ Usage
Let’s begin by discussing the project structure that Inventory expects you
to use. It’s pretty much exactly the same as the standard Ruby project
structure¹:
├── README
├── Rakefile
├── lib
│ ├── foo-1.0
│ │ ├── bar.rb
│ │ └── version.rb
│ └── foo-1.0.rb
└── test
└── unit
├── foo-1.0
│ ├── bar.rb
│ └── version.rb
└── foo-1.0.rb
Here you see a simplified version of a project called “Foo”’s project
structure. The only real difference from the standard is that the main
entry point into the library is named “foo-1.0.rb” instead of “foo.rb” and
that the root sub-directory of “lib” is similarly named “foo-1.0” instead
of “foo”. The difference is the inclusion of the API version. This must
be the major version of the project followed by a constant “.0”. The
reason for this is that it allows concurrent installations of different
major versions of the project and means that the wrong version will never
accidentally be loaded with require.
There’s a bigger difference in the content of the files.
‹Lib/foo-1.0/version.rb› will contain our inventory instead of a String:
require 'inventory-1.0'
class Foo
Version = Foo.new(1, 4, 0){
authors{
author 'A. U. Thor', 'a.u.thor@example.org'
}
homepage 'http://example.org/'
licenses{
license 'LGPLv3+',
'GNU Lesser General Public License, version 3 or later',
'http://www.gnu.org/licenses/'
}
def dependencies
super + Dependencies.new{
development 'baz', 1, 3, 0
runtime 'goo', 2, 0, 0
optional 'roo-loo', 3, 0, 0, :feature => 'roo-loo'
}
end
def package_libs
%w[bar.rb]
end
}
end
We’re introducing quite a few concepts at once, and we’ll look into each in
greater detail, but we begin by setting the ‹Version› constant to a new
instance of an Inventory with major, minor, and patch version atoms 1, 4,
and 0. Then we add a couple of dependencies and list the library files
that are included in this project.
The version numbers shouldn’t come as a surprise. These track the version
of the API that we’re shipping using {semantic versioning}². They also
allow the Inventory#to_s method to act as if you’d defined Version as
‹'1.4.0'›.
Next follows information about the authors of the project, the project’s
homepage, and the project’s licenses. Each author has a name and an email
address. The homepage is simply a string URL. Licenses have an
abbreviation, a name, and a URL where the license text can be found.
We then extend the definition of ‹dependencies› by adding another set of
dependencies to ‹super›. ‹Super› includes a dependency on the version of
the inventory project that’s being used with this project, so you’ll never
have to list that yourself. The other three dependencies are all of
different kinds: development, runtime, and optional. A development
dependency is one that’s required while developing the project, for
example, a unit-testing framework, a documentation generator, and so on.
Runtime dependencies are requirements of the project to be able to run,
both during development and when installed. Finally, optional dependencies
are runtime dependencies that may or may not be required during execution.
The difference between runtime and optional is that the inventory won’t try
to automatically load an optional dependency, instead leaving that up to
you to do when and if it becomes necessary. By that logic, runtime
dependencies will be automatically loaded, which is a good reason for
having dependency information available at runtime.
The version numbers of dependencies also use semantic versioning, but note
that the patch atom is ignored unless the major atom is 0. You should
always only depend on the major and minor atoms.
As mentioned, runtime dependencies will be automatically loaded and the
feature they try to load is based on the name of the dependency with a
“-X.0” tacked on the end, where ‘X’ is the major version of the dependency.
Sometimes, this isn’t correct, in which case the :feature option may be
given to specify the name of the feature.
You may also override other parts of a dependency by passing in a block to
the dependency, much like we’re doing for inventories.
The rest of an inventory will list the various files included in the
project. This project only consists of one additional file to those that
an inventory automatically include (Rakefile, README, the main entry point,
and the version.rb file that defines the inventory itself), namely the
library file ‹bar.rb›. Library files will be loaded automatically when the
main entry point file loads the inventory. Library files that shouldn’t be
loaded may be listed under a different heading, namely “additional_libs”.
Both these sets of files will be used to generate a list of unit test files
automatically, so each library file will have a corresponding unit test
file in the inventory. We’ll discuss the different headings of an
inventory in more detail later on.
Now that we’ve written our inventory, let’s set it up so that it’s content
gets loaded when our main entry point gets loaded. We add the following
piece of code to ‹lib/foo-1.0.rb›:
module Foo
load File.expand_path('../foo-1.0/version.rb', __FILE__)
Version.load
end
That’s all there’s to it.
The inventory can also be used to great effect from a Rakefile using a
separate project called Inventory-Rake³. Using it’ll give us tasks for
cleaning up our project, compiling extensions, installing dependencies,
installing and uninstalling the project itself, and creating and pushing
distribution files to distribution points.
require 'inventory-rake-1.0'
load File.expand_path('../lib/foo-1.0/version.rb', __FILE__)
Inventory::Rake::Tasks.define Foo::Version
Inventory::Rake::Tasks.unless_installing_dependencies do
require 'lookout-rake-3.0'
Lookout::Rake::Tasks::Test.new
end
It’s ‹Inventory::Rake::Tasks.define› that does the heavy lifting. It takes
our inventory and sets up the tasks mentioned above.
As we want to be able to use our Rakefile to install our dependencies for
us, the rest of the Rakefile is inside the conditional
#unless_installing_dependencies, which, as the name certainly implies,
executes its block unless the task being run is the one that installs our
dependencies. This becomes relevant when we set up Travis⁴ integration
next. The only conditional set-up we do in our Rakefile is creating our
test task via Lookout-Rake⁵, which also uses our inventory to find the unit
tests to run when executed.
Travis integration is straightforward. Simply put
before_script:
- gem install inventory-rake -v '~> VERSION' --no-rdoc --no-ri
- rake gem:deps:install
in the project’s ‹.travis.yml› file, replacing ‹VERSION› with the version
of Inventory-Rake that you require. This’ll make sure that Travis installs
all development, runtime, and optional dependencies that you’ve listed in
your inventory before running any tests.
You might also need to put
env:
- RUBYOPT=rubygems
in your ‹.travis.yml› file, depending on how things are set up.
¹ Ruby project structure: http://guides.rubygems.org/make-your-own-gem/
² Semantic versioning: http://semver.org/
³ Inventory-Rake: http://disu.se/software/inventory-rake-1.0/
⁴ Travis: http://travis-ci.org/
⁵ Lookout-Rake: http://disu.se/software/lookout-rake-3.0/
§ API
If the guide above doesn’t provide you with all the answers you seek, you
may refer to the API¹ for more answers.
¹ See http://disu.se/software/inventory-1.0/api/Inventory/
§ Financing
Currently, most of my time is spent at my day job and in my rather busy
private life. Please motivate me to spend time on this piece of software
by donating some of your money to this project. Yeah, I realize that
requesting money to develop software is a bit, well, capitalistic of me.
But please realize that I live in a capitalistic society and I need money
to have other people give me the things that I need to continue living
under the rules of said society. So, if you feel that this piece of
software has helped you out enough to warrant a reward, please PayPal a
donation to now@disu.se¹. Thanks! Your support won’t go unnoticed!
¹ Send a donation:
https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=now@disu.se&item_name=Inventory
§ Reporting Bugs
Please report any bugs that you encounter to the {issue tracker}¹.
¹ See https://github.com/now/inventory/issues
§ Authors
Nikolai Weibull wrote the code, the tests, the documentation, and this
README.
§ Licensing
Inventory is free software: you may redistribute it and/or modify it under
the terms of the {GNU Lesser General Public License, version 3}¹ or later²,
as published by the {Free Software Foundation}³.
¹ See http://disu.se/licenses/lgpl-3.0/
² See http://gnu.org/licenses/
³ See http://fsf.org/
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
Activity
0.0
Inventory-Rake
Inventory-Rake provides Rake¹ tasks for your Inventory². This includes tasks
for cleaning up our project, compiling extensions, installing dependencies,
installing and uninstalling the project itself, and creating and pushing
distribution files to distribution points.
¹ See http://rake.rubyforge.org/
² See http://disu.se/software/inventory-1.0/
§ Installation
Install Inventory-Rake with
% gem install inventory-rake
§ Usage
Include the following code in your ‹Rakefile›, where ‹Package› is the
top-level module of your project:
require 'inventory-rake-3.0'
load File.expand_path('../lib/package/version.rb', __FILE__)
Inventory::Rake::Tasks.define Package::Version
Inventory::Rake::Tasks.unless_installing_dependencies do
# Any additional tasks that your project’s dependencies provide
end
‹Inventory::Rake::Tasks.define› does the heavy lifting. It takes our
inventory and sets up the tasks mentioned above. We also do some
additional customization of the gem specification.
As we want to be able to use our Rakefile to install our dependencies for
us, the rest of the Rakefile is inside the conditional
#unless_installing_dependencies, which, as the name certainly implies,
executes its block unless the task being run is the one that installs our
dependencies. This becomes relevant if we want to, for example, set up
Travis¹ integration. To do so, simply add
before_script:
- gem install inventory-rake -v '~> VERSION' --no-rdoc --no-ri
- rake gem:deps:install
to your ‹.travis.yml› file. This’ll make sure that Travis installs all
development, runtime, and optional dependencies that you’ve listed in your
inventory before running any tests.
There’s more information in the {API documentation}² that you’ll likely
want to read up on if anything is unclear.
¹ See http://travis-ci.org/
² See http://disu.se/software/inventory-rake-1.0/api/Inventory/Rake/
§ Tasks
The tasks that are created if you use Inventory-Rake are:
= check. = Check that the package meets its expectations.
= mostlyclean. = Delete targets built by rake that are ofter rebuilt.
= clean. = Delete targets built by rake; depends on mostlyclean.
= distclean. = Delete all files not meant for distribution; depends on clean.
= compile. = Compile all extensions; depends on each compile:name.
= compile:name. = Compile extension /name/; depends on
lib/path/so file.
= lib/path/so. = Installed dynamic library of extension /name/ inside
inventory path; depends on ext/name/so.
= ext/name/so. = Dynamic library of extension /name/; depends on
ext/name/Makefile and the source files of the extension.
= ext/name/Makefile. = Makefile for extension /name/; depends on inventory
path, ext/name/extconf.rb file, and ext/name/depend file. Will be
created by extconf.rb, which may take options from environment variable
name#upcase_EXTCONF_OPTIONS or ‹EXTCONF_OPTIONS› if defined.
= clean:name. = Clean files built for extension /name/; depended upon by
clean.
= spec. = Create specifications; depends on gem:spec.
= gem:spec. = Create gem specification; depends on gemspec.
= gemspec (file). = Gem specification file; depends on Rakefile, README, and
inventory path.
= dist. = Create files for distribution; depends on gem:dist.
= gem:dist. = Create gem for distribution; depends on inventory:check and gem
file.
= inventory:check. = Check that the inventory is correct by looking for files
not listed in the inventory that match the pattern and for files listed
in the inventory that don’t exist; depends on distclean.
= gem (file). = Gem file; depends on files included in gem.
= dist:check. = Check files before distribution; depends on dist and
gem:dist:check.
= gem:dist:check. = Check gem before distribution; depends on gem:dist.
= deps:install. = Install dependencies on the local system; depends on
gem:deps:install.
= gem:deps:install. = Install dependencies in ruby gem directory.
= deps:install:user. = Install dependencies for the current user; depends on
gem:deps:install:user.
= gem:deps:install:user. = Install dependencies in the user gem directory.
= install. = Install distribution files on the local system; depends on
gem:install.
= gem:install. = Install gem in ruby gem directory; depends on gem:dist.
= install:user. = Install distribution files for the current user; depends on
gem:install:user.
= gem:install:user. = Install gem in the user gem directory.
= uninstall. = Delete all files installed on the local system.
= gem:uninstall. = Uninstall gem from ruby gem directory.
= uninstall:user. = Delete all files installed for current user.
= gem:uninstall:user. = Uninstall gem from ruby gem directory.
= push. = Push distribution files to distribution hubs.
= gem:push. = Push gem to rubygems.org.
§ Financing
Currently, most of my time is spent at my day job and in my rather busy
private life. Please motivate me to spend time on this piece of software
by donating some of your money to this project. Yeah, I realize that
requesting money to develop software is a bit, well, capitalistic of me.
But please realize that I live in a capitalistic society and I need money
to have other people give me the things that I need to continue living
under the rules of said society. So, if you feel that this piece of
software has helped you out enough to warrant a reward, please PayPal a
donation to now@disu.se¹. Thanks! Your support won’t go unnoticed!
¹ Send a donation:
https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=now@disu.se&item_name=Inventory-Rake
§ Reporting Bugs
Please report any bugs that you encounter to the {issue tracker}¹.
¹ See https://github.com/now/inventory-rake/issues
§ Authors
Nikolai Weibull wrote the code, the tests, the manual pages, and this
README.
§ Licensing
Inventory-Rake is free software: you may redistribute it and/or modify it
under the terms of the {GNU Lesser General Public License, version 3}¹ or
later², as published by the {Free Software Foundation}³.
¹ See http://disu.se/licenses/lgpl-3.0/
² See http://gnu.org/licenses/
³ See http://fsf.org/
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
Activity
0.0
Inventory-Rake-Tasks-YARD
Inventory-Rake-Tasks-YARD provides Rake┬╣ tasks for YARD┬▓ using your
Inventory┬│.
┬╣ See http://rake.rubyforge.org/
┬▓ See http://yardoc.org/
┬│ See http://disu.se/software/inventory/
§ Installation
Install Inventory-Rake-Tasks-YARD with
% gem install inventory-rake-tasks-yard
§ Usage
Include the following code in your ‹Rakefile› (assuming that you’ve already
set up Inventory-Rake┬╣:
Inventory::Rake::Tasks.unless_installing_dependencies do
require 'inventory-rake-tasks-yard-1.0'
Inventory::Rake::Tasks::YARD.new
end
ThisΓÇÖll define the following tasks:
= .yardopts (file). = Create .yardopts file; depends on the file defining
this task and Rakefile.
= html. = Generate documentation in HTML format for all lib files in the
inventory; depends on .yardopts file.
‹Inventory::Rake::Tasks::YARD› takes a couple of options, but the ones you
might want to adjust are
= :options. = The options to pass to YARD; will be passed to
`Shellwords.shelljoin`.
= :globals. = The globals to pass to YARD.
= :files. = The files to process; mainly used if you want to add additional
files to process beyond the lib files in the inventory.
The options passed to YARD will be augmented with any options you list in a
file named ‹.yardopts.task›, where ‹task› is the name of the Rake task
invoking YARD, for example, ‹.yardopts.html› for the default
HTML-generating task. You can use this to add options that are local to
your installation and should thus not be listed in the Rakefile itself.
See the {API documentation}┬▓ for more information.
┬╣ See http://disu.se/software/inventory-rake/
┬▓ See http://disu.se/software/inventory-rake-tasks-yard/api/Inventory/Rake/Tasks/YARD/
§ Financing
Currently, most of my time is spent at my day job and in my rather busy
private life. Please motivate me to spend time on this piece of software
by donating some of your money to this project. Yeah, I realize that
requesting money to develop software is a bit, well, capitalistic of me.
But please realize that I live in a capitalistic society and I need money
to have other people give me the things that I need to continue living
under the rules of said society. So, if you feel that this piece of
software has helped you out enough to warrant a reward, please PayPal a
donation to now@disu.se┬╣. Thanks! Your support wonΓÇÖt go unnoticed!
┬╣ Send a donation:
https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=now%40disu%2ese&item_name=Inventory-Rake-Tasks-YARD
§ Reporting Bugs
Please report any bugs that you encounter to the {issue tracker}┬╣.
┬╣ See https://github.com/now/inventory-rake-tasks-yard/issues
§ Authors
Nikolai Weibull wrote the code, the tests, the manual pages, and this
README.
§ Licensing
Inventory-Rake-Tasks-YARD is free software: you may redistribute it and/or
modify it under the terms of the {GNU Lesser General Public License,
version 3}┬╣ or later┬▓, as published by the {Free Software Foundation}┬│.
┬╣ See http://disu.se/licenses/lgpl-3.0/
┬▓ See http://gnu.org/licenses/
┬│ See http://fsf.org/
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
Activity
0.0
Lookout-Rack
Lookout-Rack provides easy interaction with Rack┬╣ from Lookout┬▓. It provides
you with a session connected to your Rack application through which you can
make requests, check responses, follow redirects and set, inspect, and clear
cookies.
┬╣ See http://rack.rubyforge.org/
┬▓ See http://disu.se/software/lookout/
§ Installation
Install Lookout-Rack with
% gem install lookout-rack
§ Usage
Include the following code in your ‹Rakefile› (provided that you’re using
Lookout-Rake┬╣):
require 'lookout-rack-3.0'
Lookout::Rake::Tasks::Test.new do |t|
t.requires << 'lookout-rack-3.0'
end
┬╣ See http://disu.se/software/lookout-rake/
Then set up a ‹fixtures/config.ru› file that Lookout-Rack
will use for loading your Rack app.
load 'path/to/app.rb'
use Rack::Lint
run Path::To::App
This file, if it exists, will be loaded during the first call to #session.
If it doesn’t exist, ‹config.ru› will be used instead.
You can now test your app:
Expectations do
expect 200 do
session.get('/').response.status
end
end
The #session method returns an object that lets you #get, #post, #put, and
#delete resources from the Rack app. You call these method with a URI┬╣
that you want to access/modify together with any parameters that you want
to pass and any Rack environment that you want to use (which isnΓÇÖt very
common). For example, let’s get ‹/pizzas/› with olives on them:
expect 200 do
session.get('/pizzas/', 'olives' => '1').response.status
end
┬╣ Abbreviation for Uniform Resource Identifier
The #response method on #session returns a mock Rack response object that
can be queried for results. Similarly, thereΓÇÖs a #request method that lets
you inspect the request that was made.
Lookout-Rack also deals with cookies. Assuming that ‹/cookies/set/› will
set any cookies that we pass it and that ‹/cookies/show/› will simply do
nothing relevant, the following expectation will pass:
expect 'value' => '1' do
session.
get('/cookies/set/', 'value' => '1').
get('/cookies/show/').request.cookies
end
Sometimes you may want to set cookies yourself before making a request.
You then use the #cookie method, which takes a String of ‹KEY=VALUE› pairs
separated by newlines, commas, and/or semicolons and sets those cookies in
the session:
expect 'value' => '1', 'other' => '2' do
session.
cookie("value=1\n\nother=2").
get('/cookies/show/').request.cookies
end
You may also want to clear all cookies in your session using #clear:
expect({}) do
session.
get('/cookies/set', 'value' => '1').
clear.
get('/cookies/show').request.cookies
end
Finally, to test redirects, call the #redirect! method on the session
object, assuming that ‹/redirected/› redirects to another location:
expect result.redirect? do
session.get('/redirected/').response
end
expect result.not.redirect? do
session.get('/redirected/').redirect!.response
end
ThatΓÇÖs basically all thereΓÇÖs to it. You can check the {API documentation}┬╣
for more information.
┬╣ See http://disu.se/software/lookout-rack/api/Lookout/Rack/
§ Financing
Currently, most of my time is spent at my day job and in my rather busy
private life. Please motivate me to spend time on this piece of software
by donating some of your money to this project. Yeah, I realize that
requesting money to develop software is a bit, well, capitalistic of me.
But please realize that I live in a capitalistic society and I need money
to have other people give me the things that I need to continue living
under the rules of said society. So, if you feel that this piece of
software has helped you out enough to warrant a reward, please PayPal a
donation to now@disu.se┬╣. Thanks! Your support wonΓÇÖt go unnoticed!
┬╣ Send a donation:
https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=now@disu.se&item_name=Lookout-Rack
§ Reporting Bugs
Please report any bugs that you encounter to the {issue tracker}┬╣.
┬╣ See https://github.com/now/lookout-rack/issues
§ Authors
Nikolai Weibull wrote the code, the tests, the documentation, and this
README.
§ Licensing
Lookout-Rack is free software: you may redistribute it and/or modify it
under the terms of the {GNU Lesser General Public License, version 3}┬╣ or
later┬▓, as published by the {Free Software Foundation}┬│.
┬╣ See http://disu.se/licenses/lgpl-3.0/
┬▓ See http://gnu.org/licenses/
┬│ See http://fsf.org/
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
Activity
0.0
Lookout-Rake
Lookout-Rake provides Rake┬╣ tasks for testing using Lookout.
┬╣ See http://rake.rubyforge.org/
§ Installation
Install Lookout-Rake with
% gem install lookout-rake
§ Usage
Include the following code in your ‹Rakefile›:
require 'lookout-rake-3.0'
Lookout::Rake::Tasks::Test.new
If the ‹:default› task hasn’t been defined it’ll be set to depend on the
‹:test› task. The ‹:check› task will also depend on the ‹:test› task.
There’s also a ‹:test:coverage› task that gets defined that uses the
coverage library that comes with Ruby 1.9 to check the test coverage when
the tests are run.
You can hook up your test task to use your Inventory┬╣:
load File.expand_path('../lib/library-X.0/version.rb', __FILE__)
Lookout::Rake::Tasks::Test.new :inventory => Library::Version
Also, if you use the tasks that come with Inventory-Rake┬▓, the test task
will hook into the inventory you tell them to use automatically, that is,
the following will do:
load File.expand_path('../lib/library-X.0/version.rb', __FILE__)
Inventory::Rake::Tasks.define Library::Version
Lookout::Rake::Tasks::Test.new
For further usage information, see the {API documentation}┬│.
┬╣ Inventory: http://disu.se/software/inventory/
┬▓ Inventory-Rake: http://disu.se/software/inventory-rake/
┬│ API: http://disu.se/software/lookout-rake/api/Lookout/Rake/Tasks/Test/
§ Integration
To use Lookout together with Vim¹, place ‹contrib/rakelookout.vim› in
‹~/.vim/compiler› and add
compiler rakelookout
to ‹~/.vim/after/ftplugin/ruby.vim›. Executing ‹:make› from inside Vim
will now run your tests and an errors and failures can be visited with
‹:cnext›. Execute ‹:help quickfix› for additional information.
Another useful addition to your ‹~/.vim/after/ftplugin/ruby.vim› file may
be
nnoremap <buffer> <silent> <Leader>M <Esc>:call <SID>run_test()<CR>
let b:undo_ftplugin .= ' | nunmap <buffer> <Leader>M'
function! s:run_test()
let test = expand('%')
let line = 'LINE=' . line('.')
if test =~ '^lib/'
let test = substitute(test, '^lib/', 'test/', '')
let line = ""
endif
execute 'make' 'TEST=' . shellescape(test) line
endfunction
Now, pressing ‹<Leader>M› will either run all tests for a given class, if
the implementation file is active, or run the test at or just before the
cursor, if the test file is active. This is useful if youΓÇÖre currently
receiving a lot of errors and/or failures and want to focus on those
associated with a specific class or on a specific test.
┬╣ Find out more about Vim at http://www.vim.org/
§ Financing
Currently, most of my time is spent at my day job and in my rather busy
private life. Please motivate me to spend time on this piece of software
by donating some of your money to this project. Yeah, I realize that
requesting money to develop software is a bit, well, capitalistic of me.
But please realize that I live in a capitalistic society and I need money
to have other people give me the things that I need to continue living
under the rules of said society. So, if you feel that this piece of
software has helped you out enough to warrant a reward, please PayPal a
donation to now@disu.se┬╣. Thanks! Your support wonΓÇÖt go unnoticed!
┬╣ Send a donation:
https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=now%40disu%2ese&item_name=Nikolai%20Weibull%20Software%20Services
§ Reporting Bugs
Please report any bugs that you encounter to the {issue tracker}┬╣.
┬╣ See https://github.com/now/lookout-rake/issues
§ Authors
Nikolai Weibull wrote the code, the tests, the manual pages, and this
README.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
Activity
0.0
# RbTags #
RbTags is a replacement for ctags (and rtags) for Ruby.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
Activity
0.0
U
U extends Ruby’s Unicode support. It provides a string class called
U::String with an interface that mimics that of the String class in Ruby 2.0,
but that can also be used from both Ruby 1.8. This interface also has more
complete Unicode support and never modifies the receiver. Thus, a U::String
is an immutable value object.
U comes with complete and very accurate documentation¹. The documentation can
realistically also be used as a reference to the Ruby String API and may
actually be preferable, as it’s a lot more explicit and complete than the
documentation that comes with Ruby.
¹ See http://disu.se/software/u-1.0/api/
§ Installation
Install u with
% gem install u
§ Usage
Usage is basically the following:
require 'u-1.0'
a = 'äbc'
a.upcase # ⇒ 'äBC'
a.u.upcase # ⇒ 'ÄBC'
That is, you require the library, then you invoke #u on a String. This’ll
give you a U::String that has much better Unicode support than a normal
String. It’s important to note that U only uses UTF-8, which means that #u
will try to #encode the String as such. This shouldn’t be an issue in most
cases, as UTF-8 is now more or less the universal encoding – and rightfully
so.
As U::Strings¹ are immutable value objects, there’s also a U::Buffer²
available for building U::Strings efficiently.
See the API³ for more complete usage information. The following sections
will only cover the extensions and differences that U::String exhibit from
Ruby’s built-in String class.
¹ See http://disu.se/software/u-1.0/api/U/String/
² See http://disu.se/software/u-1.0/api/U/Buffer/
³ See http://disu.se/software/u-1.0/api/
§ Unicode Properties
There are quite a few property-checking interrogators that let you check
if all characters in a U::String have the given Unicode property:
• #alnum?¹
• #alpha?²
• #assigned?³
• #case_ignorable?⁴
• #cased?⁵
• #cntrl?⁶
• #defined?⁷
• #digit?⁸
• #graph?⁹
• #newline?¹⁰
• #print?¹¹
• #punct?¹²
• #soft_dotted?¹³
• #space?¹⁴
• #title?¹⁵
• #valid?¹⁶
• #wide?¹⁷
• #wide_cjk?¹⁸
• #xdigit?¹⁹
• #zero_width?²⁰
¹ See http://disu.se/software/u-1.0/api/U/String/#alnum-p-instance-method
² See http://disu.se/software/u-1.0/api/U/String/#alpha-p-instance-method
³ See http://disu.se/software/u-1.0/api/U/String/#assigned-p-instance-method
⁴ See http://disu.se/software/u-1.0/api/U/String/#case_ignorable-p-instance-method
⁵ See http://disu.se/software/u-1.0/api/U/String/#cased-p-instance-method
⁶ See http://disu.se/software/u-1.0/api/U/String/#cntrl-p-instance-method
⁷ See http://disu.se/software/u-1.0/api/U/String/#defined-p-instance-method
⁸ See http://disu.se/software/u-1.0/api/U/String/#digit-p-instance-method
⁹ See http://disu.se/software/u-1.0/api/U/String/#graph-p-instance-method
¹⁰ See http://disu.se/software/u-1.0/api/U/String/#newline-p-instance-method
¹¹ See http://disu.se/software/u-1.0/api/U/String/#print-p-instance-method
¹² See http://disu.se/software/u-1.0/api/U/String/#punct-p-instance-method
¹³ See http://disu.se/software/u-1.0/api/U/String/#soft_dotted-p-instance-method
¹⁴ See http://disu.se/software/u-1.0/api/U/String/#space-p-instance-method
¹⁵ See http://disu.se/software/u-1.0/api/U/String/#title-p-instance-method
¹⁶ See http://disu.se/software/u-1.0/api/U/String/#valid-p-instance-method
¹⁷ See http://disu.se/software/u-1.0/api/U/String/#wide-p-instance-method
¹⁸ See http://disu.se/software/u-1.0/api/U/String/#wide_cjk-p-instance-method
¹⁹ See http://disu.se/software/u-1.0/api/U/String/#xdigit-p-instance-method
²⁰ See http://disu.se/software/u-1.0/api/U/String/#zero_width-p-instance-method
Similar to these methods are
• #folded?¹
• #lower?²
• #upper?³
which check whether a ‹U::String› has been cased in a given manner.
¹ See http://disu.se/software/u-1.0/api/U/String/#folded-p-instance-method
² See http://disu.se/software/u-1.0/api/U/String/#lower-p-instance-method
³ See http://disu.se/software/u-1.0/api/U/String/#upper-p-instance-method
There’s also a #normalized?¹ method that checks whether a ‹U::String› has
been normalized on a given form.
¹ See http://disu.se/software/u-1.0/api/U/String/#normalized-p-instance-method
You can also access certain Unicode properties of the characters of a
U::String:
• #canonical_combining_class¹
• #general_category²
• #grapheme_break³
• #line_break⁴
• #script⁵
• #word_break⁶
¹ See http://disu.se/software/u-1.0/api/U/String/#canonical_combining_class-instance-method
² See http://disu.se/software/u-1.0/api/U/String/#general_category-instance-method
³ See http://disu.se/software/u-1.0/api/U/String/#grapheme_break-instance-method
⁴ See http://disu.se/software/u-1.0/api/U/String/#line_break-instance-method
⁵ See http://disu.se/software/u-1.0/api/U/String/#script-instance-method
⁶ See http://disu.se/software/u-1.0/api/U/String/#word_break-instance-method
§ Locale-specific Comparisons
Comparisons of U::Strings respect the current locale (and also allow you
to specify a locale to use): ‹#<=>›¹, #casecmp², and #collation_key³.
¹ See http://disu.se/software/u-1.0/api/U/String/#comparison-operator
² See http://disu.se/software/u-1.0/api/U/String/#casecmp-instance-method
³ See http://disu.se/software/u-1.0/api/U/String/#collation_key-instance-method
§ Additional Enumerators
There are a couple of additional enumerators in #each_grapheme_cluster¹
and #each_word² (along with aliases #grapheme_clusters³ and #words⁴).
¹ See http://disu.se/software/u-1.0/api/U/String/#each_grapheme_cluster-instance-method
² See http://disu.se/software/u-1.0/api/U/String/#each_word-instance-method
³ See http://disu.se/software/u-1.0/api/U/String/#grapheme_clusters-instance-method
⁴ See http://disu.se/software/u-1.0/api/U/String/#words-instance-method
§ Unicode-aware Sub-sequence Removal
#Chomp¹, #chop², #lstrip³, #rstrip⁴, and #strip⁵ all look for Unicode
newline and space characters, rather than only ASCII ones.
¹ See http://disu.se/software/u-1.0/api/U/String/#chomp-instance-method
² See http://disu.se/software/u-1.0/api/U/String/#chop-instance-method
³ See http://disu.se/software/u-1.0/api/U/String/#lstrip-instance-method
⁴ See http://disu.se/software/u-1.0/api/U/String/#rstrip-instance-method
⁵ See http://disu.se/software/u-1.0/api/U/String/#strip-instance-method
§ Unicode-aware Conversions
Case-shifting methods #downcase¹ and #upcase² do proper Unicode casing
and the interface is further augmented by #foldcase³ and #titlecase⁴.
#Mirror⁵ and #normalize⁶ do conversions similar in nature to the
case-shifting methods.
¹ See http://disu.se/software/u-1.0/api/U/String/#downcase-instance-method
² See http://disu.se/software/u-1.0/api/U/String/#upcase-instance-method
³ See http://disu.se/software/u-1.0/api/U/String/#foldcase-instance-method
⁴ See http://disu.se/software/u-1.0/api/U/String/#titlecase-instance-method
⁵ See http://disu.se/software/u-1.0/api/U/String/#mirror-instance-method
⁶ See http://disu.se/software/u-1.0/api/U/String/#normalize-instance-method
§ Width Calculations
#Width¹ will return the number of cells on a terminal that a U::String
will occupy.
#Center², #ljust³, and #rjust⁴ deal in width rather than length, making
them much more useful for generating terminal output. #%⁵ (and its alias
#format⁶) similarly deal in width.
¹ See http://disu.se/software/u-1.0/api/U/String/#width-instance-method
² See http://disu.se/software/u-1.0/api/U/String/#center-instance-method
³ See http://disu.se/software/u-1.0/api/U/String/#ljust-instance-method
⁴ See http://disu.se/software/u-1.0/api/U/String/#rjust-instance-method
⁵ See http://disu.se/software/u-1.0/api/U/String/#modulo-operator
⁶ See http://disu.se/software/u-1.0/api/U/String/#format-instance-method
§ Extended Type Conversions
Finally, #hex¹, #oct², and #to_i³ use Unicode alpha-numerics for their
respective conversions.
¹ See http://disu.se/software/u-1.0/api/U/String/#hex-instance-method
² See http://disu.se/software/u-1.0/api/U/String/#oct-instance-method
³ See http://disu.se/software/u-1.0/api/U/String/#to_i-instance-method
§ News
§ 1.0.0
Initial public release!
§ Financing
Currently, most of my time is spent at my day job and in my rather busy
private life. Please motivate me to spend time on this piece of software
by donating some of your money to this project. Yeah, I realize that
requesting money to develop software is a bit, well, capitalistic of me.
But please realize that I live in a capitalistic society and I need money
to have other people give me the things that I need to continue living
under the rules of said society. So, if you feel that this piece of
software has helped you out enough to warrant a reward, please PayPal a
donation to now@disu.se¹. Thanks! Your support won’t go unnoticed!
¹ Send a donation:
https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=now@disu.se&item_name=U
§ Reporting Bugs
Please report any bugs that you encounter to the {issue tracker}¹.
¹ See https://github.com/now/u/issues
§ Authors
Nikolai Weibull wrote the code, the tests, the documentation, and this
README.
§ Licensing
U is free software: you may redistribute it and/or modify it under the
terms of the {GNU Lesser General Public License, version 3}¹ or later², as
published by the {Free Software Foundation}³.
¹ See http://disu.se/licenses/lgpl-3.0/
² See http://gnu.org/licenses/
³ See http://fsf.org/
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
Activity
0.0
Value
Value is a library for defining immutable value objects in Ruby. A value
object is an object whose equality to other objects is determined by its
value, not its identity, think dates and amounts of money. A value object
should also be immutable, as you donΓÇÖt want the date ΓÇ£2013-04-22ΓÇ¥ itself to
change but the current date to change from ΓÇ£2013-04-22ΓÇ¥ to ΓÇ£2013-04-23ΓÇ¥.
That is, you donΓÇÖt want entries in a calendar for 2013-04-22 to move to
2013-04-23 simply because the current date changes from 2013-04-22 to
2013-04-23.
A value object consists of one or more attributes stored in instance
variables. Value sets up an #initialize method for you that letΓÇÖs you set
these attributes, as, value objects being immutable, thisΓÇÖll be your only
chance to do so. Value also adds equality checks ‹#==› and ‹#eql?› (which
are themselves equivalent), a ‹#hash› method, a nice ‹#inspect› method, and a
protected attribute reader for each attribute. You may of course add any
additional methods that your value object will benefit from.
ThatΓÇÖs basically all thereΓÇÖs too it. LetΓÇÖs now look at using the Value
library.
§ Usage
You create value object class by invoking ‹#Value› inside the class
(module) you wish to make into a value object class. LetΓÇÖs create a class
that represent points on a plane:
class Point
Value :x, :y
end
A ‹Point› is thus a value object consisting of two sub-values ‹x› and ‹y›
(the coordinates). Just from invoking ‹#Value›, a ‹Point› object will have
a constructor that takes two arguments to set instance variables ‹@x› and
‹@y›, equality checks ‹#==› and ‹#eql?› (which are the same), a ‹#hash›
method, a nice ‹#inspect› method, and two protected attribute readers ‹#x›
and ‹#y›. We can thus already creat ‹Point›s:
origo = Point.new(0, 0)
The default of making the attribute readers protected is often good
practice, but for a ‹Point› it probably makes sense to be able to access
its coordinates:
class Point
public(*attributes)
end
This’ll make all attributes of ‹Point› public. You can of course choose to
only make certain attributes public:
class Point
public :x
end
Note that this public is standard Ruby functionality. Adding a method to
‹Point› is of course also possible and very much Rubyish:
class Point
def distance(other)
Math.sqrt((other.x - x)**2 + (other.y - y)**2)
end
end
For some value object classes you might want to support optional
attributes. This is done by providing a default value for the attribute,
like so:
class Money
Value :amount, [:currency, :USD]
end
Here, the ‹currency› attribute will default to ‹:USD›. You can create
‹Money› via
dollars = Money.new(2)
but also
kronor = Money.new(2, :SEK)
All required attributes must come before any optional attributes.
Splat attributes are also supported:
class List
Value :'*elements'
end
empty = List.new
suits = List.new(:spades, :hearts, :diamonds, :clubs)
Splat attributes are optional.
Finally, block attributes are also available:
class Block
Value :'&block'
end
block = Block.new{ |e| e * 2 }
Block attributes are optional.
Comparison beyond ‹#==› is possible by specifingy the ‹:comparable› option
to ‹#Value›, listing one or more attributes that should be included in the
comparison:
class Vector
Value :a, :b, :comparable => :a
end
Note that equality (‹#==› and ‹#eql?›) is always defined based on all
attributes, regardless of arguments to ‹:comparable›.
Here we say that comparisons between ‹Vector›s should be made between the
values of the ‹a› attribute only. We can also make comparisons between all
attributes of a value object:
class Vector
Value :a, :b, :comparable => true
end
To sum things up, let’s use all possible arguments to ‹#Value› at once:
class Method
Value :file, :line, [:name, 'unnamed'], :'*args', :'&block',
:comparable => [:file, :line]
end
A ‹Method› consists of file and line information, a possible name, some
arguments, possibly a block, and is comparable on the file and line on
which they appear.
Check out the {full API documentation}┬╣ for a more explicit description,
should you need it or should you want to extend it.
┬╣ See http://disu.se/software/value/api/
§ Financing
Currently, most of my time is spent at my day job and in my rather busy
private life. Please motivate me to spend time on this piece of software
by donating some of your money to this project. Yeah, I realize that
requesting money to develop software is a bit, well, capitalistic of me.
But please realize that I live in a capitalistic society and I need money
to have other people give me the things that I need to continue living
under the rules of said society. So, if you feel that this piece of
software has helped you out enough to warrant a reward, please PayPal a
donation to now@disu.se┬╣. Thanks! Your support wonΓÇÖt go unnoticed!
┬╣ Send a donation:
https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=now%40disu%2ese&item_name=Value
§ Reporting Bugs
Please report any bugs that you encounter to the {issue tracker}┬╣.
┬╣ See https://github.com/now/value/issues
§ Authors
Nikolai Weibull wrote the code, the tests, the manual pages, and this
README.
§ Licensing
Value is free software: you may redistribute it and/or modify it under the
terms of the {GNU Lesser General Public License, version 3}┬╣ or later┬▓, as
published by the {Free Software Foundation}┬│.
┬╣ See http://disu.se/licenses/lgpl-3.0/
┬▓ See http://gnu.org/licenses/
┬│ See http://fsf.org/
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
Activity
0.0
Value-YARD
Value-YARD provides YARD handlers for Value¹ objects.
¹ Check out the Value library at http://disu.se/software/value
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
Activity
0.0
YARD-Heuristics
YARD-Heuristics heuristically determines types of parameters and return
values for YARD documentation that doesnΓÇÖt explicitly document it. This
allows you to write documentation that isnΓÇÖt adorned with ΓÇ£obviousΓÇ¥ types,
but still get that information into the output. It also lets you
nice-looking references to parameters and have them be marked up
appropriately in HTML output.
§ Heuristics
The following sections list the various heuristics that YARD-Heuristics
apply for determining types of parameters and return values.
Note that for all heuristics, a type will only be added if none already
exists.
§ Parameter Named “other”
A parameter named ΓÇ£otherΓÇ¥ has the same type as the receiver. This turns
class Point
def ==(other)
into
class Point
# @param [Point] other
def ==(other)
§ Parameter Types Derived by Parameter Name
Parameters to a method with names in the following table has the type
listed on the same row.
| Name | Type |
|--------+-----------|
| index | [Integer] |
| object | [Object] |
| range | [Range] |
| string | [String] |
Thus
class Point
def x_inside?(range)
becomes
class Point
# @param [Range] range
def x_inside?(range)
§ Block Parameters
If the last parameter to a methodΓÇÖs name begins with ΓÇÿ&ΓÇÖ it has the type
[Proc].
class Method
def initialize(&block)
becomes
class Method
# @param [Block] block
def initialize(&block)
§ Return Types by Method Name
For the return type of a method with less than two ‹@return› tags, the
method name is lookup up in the following table and has the type listed on
the same row. For the “type” “self or type”, if a ‹@param› tag exists with
the name ΓÇ£otherΓÇ¥, the type of the receiver is used, otherwise ΓÇ£selfΓÇ¥ is
used. For the ΓÇ£typeΓÇ¥ ΓÇ£typeΓÇ¥, the type of the receiver is used.
| Name | Type |
|-----------------+----------------|
| ‹<<› | self or type |
| ‹>>› | self or type |
| ‹==› | [Boolean] |
| ‹===› | [Boolean] |
| ‹=~› | [Boolean] |
| ‹<=>› | [Integer, nil] |
| ‹+› | type |
| ‹-› | type |
| ‹*› | type |
| ‹/› | type |
| each | [self] |
| each_with_index | [self] |
| hash | [Integer] |
| inspect | [String] |
| length | [Integer] |
| size | [Integer] |
| to_s | [String] |
| to_str | [String] |
Thus
class Point
def <<(other)
becomes
class Point
# @return [Point]
def <<(other)
but
class List
def <<(item)
becomes
class List
# @return [self]
def <<(item)
§ Emphasizing Parameter Names
When producing HTML output, any words in all uppercase, with a possible
“th” suffix, that is also the name of a parameter, an ‹@option›, or a
‹@yieldparam›, will be downcased and emphasized with a class of
ΓÇ£parameterΓÇ¥.
In the following example, ΓÇ£OTHERΓÇ¥ will be turned into
‹<em class="parameter">other</em>›:
class Point
# @return True if the receiverΓÇÖs class and {#x} and {#y} `#==` those of
# OTHER
def ==(other)
§ Usage
Add ‹--plugin yard-heuristics-1.0› to your YARD command line. If you’re
using Inventory-Rake-Tasks-YARD┬╣, add the following to your Rakefile:
Inventory::Rake::Tasks::YARD.new do |t|
t.options += %w'--plugin yard-heuristics-1.0'
end
┬╣ See http://disu.se/software/inventory-rake-tasks-yard/
§ API
ThereΓÇÖs really not very much to the YARD-Heuristics API. What you can do
is add (or modify) the types of parameters and return types of methods by
adding (or modifying) entries in the Hash tables
‹YARDHeuristics::ParamTypes› and ‹YARDHeuristics::ReturnTypes›
respectively. ThatΓÇÖs about it.
§ Financing
Currently, most of my time is spent at my day job and in my rather busy
private life. Please motivate me to spend time on this piece of software
by donating some of your money to this project. Yeah, I realize that
requesting money to develop software is a bit, well, capitalistic of me.
But please realize that I live in a capitalistic society and I need money
to have other people give me the things that I need to continue living
under the rules of said society. So, if you feel that this piece of
software has helped you out enough to warrant a reward, please PayPal a
donation to now@disu.se┬╣. Thanks! Your support wonΓÇÖt go unnoticed!
┬╣ Send a donation:
https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=now@disu.se&item_name=YARD-Heuristics
§ Reporting Bugs
Please report any bugs that you encounter to the {issue tracker}┬╣.
┬╣ See https://github.com/now/yard-heuristics/issues
§ Authors
Nikolai Weibull wrote the code, the tests, and this README.
§ Licensing
YARD-Heuristics is free software: you may redistribute it and/or modify it
under the terms of the {GNU Lesser General Public License, version 3}┬╣ or
later┬▓, as published by the {Free Software Foundation}┬│.
┬╣ See http://disu.se/licenses/lgpl-3.0/
┬▓ See http://gnu.org/licenses/
┬│ See http://fsf.org/
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
Activity
0.0
YARD-Value
YARD-Value provides YARD¹ handlers for Value² objects. It’ll document
whether the Value is Comparable and what attributes are used in such
comparisons, its #initialize method, and its protected accessors.
¹ See http://yardoc.org/
² See http://disu.se/software/value-1.0/
You add the documentation to the Module#Value invocation. Any ‹@param› tags
are used both for the parameters to the #initialize method and for the
protected accessors.
This
class Point
# A point on a plane.
# @param [Integer] x
# @param [Integer] y
Value :x, :y
end
generates documentation similar to
class Point
# A point on a plane.
# @param [Integer] x
# @param [Integer] y
def initialize(x, y)
end
and this
class Point
# A point on a plane.
# @param [Integer] x The x coordinate of the receiver
# @param [Integer] y The y coordinate of the receiver
Value :x, :y
end
generates documentation similar to
class Point
# A point on a plane.
# @param [Integer] x
# @param [Integer] y
def initialize(x, y)
protected
# @return [Integer] The x coordinate of the receiver
attr_reader :x
# @return [Integer] The y coordinate of the receiver
attr_reader :y
end
For comparable Values, a note is added about what attributes are used in the
comparison. This
class Point
# A point on a plane.
# @param [Integer] x
# @param [Integer] y
Value :x, :y, :comparable => true
end
is similar to
class Point
# A point on a plane.
# @param [Integer] x
# @param [Integer] y
# @note Comparisons between instances are made between x and y.
def initialize(x, y)
end
§ Usage
Add ‹--plugin yard-value-1.0› to your YARD command line. If you’re
using Inventory-Rake-Tasks-YARD¹, add the following to your Rakefile:
Inventory::Rake::Tasks::YARD.new do |t|
t.options += %w'--plugin yard-value-1.0'
end
¹ See http://disu.se/software/inventory-rake-tasks-yard-1.0/
§ Financing
Currently, most of my time is spent at my day job and in my rather busy
private life. Please motivate me to spend time on this piece of software
by donating some of your money to this project. Yeah, I realize that
requesting money to develop software is a bit, well, capitalistic of me.
But please realize that I live in a capitalistic society and I need money
to have other people give me the things that I need to continue living
under the rules of said society. So, if you feel that this piece of
software has helped you out enough to warrant a reward, please PayPal a
donation to now@disu.se¹. Thanks! Your support won’t go unnoticed!
¹ Send a donation:
https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=now@disu.se&item_name=YARD-Value
§ Reporting Bugs
Please report any bugs that you encounter to the {issue tracker}¹.
¹ See https://github.com/now/yard-value/issues
§ Authors
Nikolai Weibull wrote the code, the tests, and this README.
§ Licensing
YARD-Value is free software: you may redistribute it and/or modify it under
the terms of the {GNU Lesser General Public License, version 3}¹ or later²,
as published by the {Free Software Foundation}³.
¹ See http://disu.se/licenses/lgpl-3.0/
² See http://gnu.org/licenses/
³ See http://fsf.org/
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
Activity