0.0
Ruby mixin that facilitates English-like type checking in an inheritance hierarchy via "type_name?" methods
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
Activity
0.01
All the flexibility of a Ruby Struct, but with type checking on its properties. Also benefit from being able to define complex types using RBS type notation.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
Activity
0.02
A new check for puppet-lint that validates that all parameters are typed.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
Activity
0.05
Type check JSON objects
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
Activity
0.02
Type-checked serializers for your Ruby objects
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
Activity
0.0
# License
Create software licenses easily.
## Install
### Bundler: `gem 'license'`
### RubyGems: `gem install license`
## Usage
### Simple
```ruby
license = License::Software::MIT.new do |l|
l.year.start = 2012
l.author.name = 'Ryan Scott Lewis'
l.author.email = 'ryan@rynet.us'
end
p license.to_s # => "Copyright (c) 2012 Ryan Scott Lewis <ryan@rynet.us>\n\nPermission is hereby granted, free of charge..."
```
### Multiple Authors
```ruby
license = License::Software::MIT.new do |l|
l.year.start = 2012
l.authors.add name: 'Ryan Scott Lewis', email: 'ryan@rynet.us'
l.authors.add name: 'John Doe', email: 'john.doe@example.com'
l.authors.add name: 'Snake Pliskin'
l.authors.add 'John McClane <john@mcclain.org, jmcclane@gmail.com>'
end
p license.to_s # => "Copyright (c) 2012 Ryan Scott Lewis <ryan@rynet.us>, John Doe <john.doe@example.com>\n\nPermission is hereby granted, free of charge..."
p license.authors.first.name # => 'Ryan Scott Lewis'
p license.authors.first.email # => 'ryan@rynet.us'
p license.authors.last.name # => 'John McClane'
p license.authors.last.email # => 'john@mcclain.org'
p license.authors.last.emails # => ['john@mcclain.org', 'jmcclane@gmail.com]
```
#### Smart Setters
```ruby
license = License::Software.new do |l|
l.type = License::Software::MIT # Set which type of license here instead
l.year = '2006-2011' # Will set year.start to 2006 and year.end to 2011
l.authors = 'Ryan Scott Lewis<ryan@rynet>, John Doe < john.doe@example.com >'
end
p license.to_s # => "Copyright (c) 2012 Ryan Scott Lewis <ryan@rynet.us>, John Doe <john.doe@example.com>\n\nPermission is hereby granted, free of charge..."
```
#### Advanced usage (preferred method)
```ruby
license = License::Software.new do # Do not pass block variables to enter the scope of the License::Software
type MIT
year 2012
author 'Ryan Scott Lewis <ryan@rynet.us>'
end
p license.to_s # => "Copyright (c) 2012 Ryan Scott Lewis <ryan@rynet.us>\n\nPermission is hereby granted, free of charge..."
```
## Contributing
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
* Fork the project
* Start a feature/bugfix branch
* Commit and push until you are happy with your contribution
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
## Copyright
Copyright © 2012 Ryan Scott Lewis <ryan@rynet.us>.
The MIT License (MIT) - See LICENSE for further details.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
Activity
0.04
MooseX is an extension of Ruby object DSL. The main goal of MooseX is to make Ruby Object Oriented programming easier, more consistent, and less tedious. With MooseX you can think more about what you want to do and less about the mechanics of OOP. It is a port of Moose/Moo from Perl to Ruby world, providing method delegation, type check, traits, monads, plugins, lazy attributes, aspects and much more.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
Activity
0.0
A database structure reader for PostgreSQL with support for tables, fields, primary keys, indexes, foreign keys, check constraints, enum types and extensions.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
0.15
Type checking and type casting of parameters for Action Pack
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
Activity
0.0
Sinja is a Sinatra extension for quickly building RESTful,
{json:api}-compliant web services, leveraging the excellent
JSONAPI::Serializers gem for payload serialization. It enhances Sinatra's
DSL to enable resource-, relationship-, and role-centric API development,
and it configures Sinatra with the proper settings, MIME-types, filters,
conditions, and error-handling.
There are many parsing (deserializing), rendering (serializing), and other
"JSON API" libraries available for Ruby, but relatively few that attempt to
correctly implement the entire {json:api} server specification, including
routing, request header and query parameter checking, and relationship
side-loading. Sinja lets you focus on the business logic of your
applications without worrying about the specification, and without pulling
in a heavy framework like Rails. It's lightweight, ORM-agnostic, and
Ember.js-friendly!
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
Activity
0.0
Built to support all types of checkout integration between Akatus and your application
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
0.0
Basic file type checks based on a few header bytes
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
0.0
Reliable contract definition, data validation, and type checking for Ruby.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
Activity
0.0
An on-demand arbitrary check and conversion library that won't destroy your data.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
0.0
# FaradayError
[![Gem Version](https://badge.fury.io/rb/faraday_error.svg)](https://badge.fury.io/rb/faraday_error)
A [Faraday](https://github.com/lostisland/faraday) middleware for adding request parameters to your exception tracker.
### Supports
- [Honeybadger](https://www.honeybadger.io/)
- [NewRelic](http://newrelic.com/)
- Your favorite thing, as soon as you make a pull request!
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'faraday_error'
```
And then execute:
$ bundle
Or install it yourself as:
$ gem install faraday_error
## Usage
Configure your Faraday connection to use this middleware. You can optionally specify a name; defaults to `faraday`. It is expected that you also use `Faraday::Response::RaiseError` somewhere in your stack.
```ruby
connection = Faraday.new(url: 'http://localhost:4567') do |faraday|
faraday.use FaradayError::Middleware, name: "example_request"
faraday.use Faraday::Response::RaiseError
faraday.adapter Faraday.default_adapter
end
```
And that's it. Make a request as you normally would.
```ruby
connection.post do |req|
req.url '/503'
req.headers['Content-Type'] = 'application/json'
req.body = JSON.generate(abc: "xyz")
end
```
If any request fails, Honeybadger's "context" for this error will include your request parameters. If sending JSON or `application/x-www-form-urlencoded`, these will be included in parsed form.
```json
{
"example_request": {
"method": "post",
"url": "http://localhost:4567/503",
"request_headers": {
"User-Agent": "Faraday v0.9.2",
"Content-Type": "application/json"
},
"body_length": 13,
"body": {
"abc": "xyz"
}
}
}
```
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
The included [RestReflector](../master/spec/rest_reflector.rb) Sinatra app is suitable for making requests that are guaranteed to fail in particlar ways.
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/jelder/faraday_error. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
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
2025
0.0
QuacksLike is a module for RSpec to add matchers that test if an object is fully duck-typed to pretend to be another class. This kind of thing is really only necessary when passing such an object as the return value in an API where you don't know exactly how it will be consumed, but it needs to "quack like an Array" or something. It does its job by checking every instance method in the class that the target object needs to "quack like" and makes sure the target both responds to that method name and that the arity of the method is appropriate.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
Activity
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
2025
Activity
0.0
Contains validators for date and time values, type checking.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
Activity
0.0
Generate all parts of a compiler, including the lexer, parser, syntax tree, symbol table, type checker, code generator, and optimizer.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
Activity