0.0
Only 70 lines. Add a optional type system to ruby using runtime checks and contracts . make it crash early, know exactly what a function (or method)
returns and specify the 'type' of the parameters using good old ducktyping
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
Activity
0.0
a Rails gem that allows you to validate a URL
entered in a form. It validates if the URL exists by hitting it with a HEAD
request.
The improved version includes retries for common patterns when the head request is refused before giving a failure notice.
It also looks up a SITE_URL constant to the user agent in the headers.
Also has the option to also check that the URL returns content of
a specified type.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
0.0
Decorator style assertions and type check library for Contract programming.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
Activity
0.0
This gem adds Mobility plugin, which can be turned on for Rails model,
and will check types of values passed to setters.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
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
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
Activity
0.0
This gem is for printing hyperlinks in supported terminal emulators. It is a simple wrapper that abstracts the ANSI characters usually required to achieve this, which are annoying to type out. Check out the gist that inspired this gem at: https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
0.0
Typedeaf is a gem to help add some type-checking to method declarations in Ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
0.0
tspec can check type of methods arguments and return value.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
Activity
0.0
Taipo provides a simple way to check your variables are what you think they are. With an easy to use syntax you can call a single method and pass expressive type definitions.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
Activity
0.01
The Preconditions library provides a simple set of methods for checking arguments being passed into a method. Instead of writing custom checks and raising exceptions directly in your code you can use Preconditions to verify basic properties of your arguments (not-nil, satisfying a boolean expression, being of a certain type/duck-type) and raise the appropriate exception for you.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
0.0
Rzd is a gem automating checking ticket information for russian railway service rzd.ru. Now it allows to get available ticket types fro given cities and date.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
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
Activity
0.0
Pronto runner for Sorbet, a static type checker for Ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
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.01
Type-checked set and array
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
Activity
0.0
Return a variable if it's present (and optionally of the right type), otherwise a default or nil. Adds a top level demand() method, which replaces long lines of repetitive code to check for nil?/present?/empty?, etc., hard-to-read ternary operators (?:) and if statements. A block can also be specified, which only runs (with the variable) if the checks pass.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
Activity
0.0
This gem allows you to check the Content-Type of any HTTP-accessible asset.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
0.0
# mdtoc - Markdown Table of Contents
Read Markdown files and output a table of contents.
## Installation
Requirements:
* [Ruby](https://www.ruby-lang.org/en/) (see [.ruby-version](./.ruby-version))
```
$ gem install mdtoc
```
## Usage
```
$ mdtoc --help
Usage: mdtoc [options] files or directories...
-h, --help Show this message
-o, --output PATH Update a table of contents in the file at PATH
-a, --[no-]append Append to the --output file if a <!-- mdtoc --> tag isn't found
-c, --[no-]create Create the --output file if it does not exist
```
1. Add a `<!-- mdtoc -->` tag to a Markdown file.
```
$ echo '<!-- mdtoc -->` >> README.md
```
2. Run `mdtoc` and specify input files or directories (eg. the "test/samples" directory) and an output file (eg. "README.md").
```
$ mdtoc -aco README.md test/samples
```
## Example Rakefile
Create a `Rakefile` with the contents below, then run
[`rake`](https://github.com/ruby/rake) to:
* `git pull`
* `git add` any *.md files
* Run `mdtoc` to update the generated table of contents in the ./README.md file
* Git commit and push any changes
```
task default: %w[mdtoc]
desc 'Update Markdown table of contents and push changes to the git repository'
task :mdtoc do |t|
command = <<~END
set -e
git pull
if [ -n "$(git diff --name-only --diff-filter=U)" ]; then
echo 'Error: conflicts exist' >&2
exit 1
fi
mdtoc --append --create --output README.md docs/
git add *.md **/*.md
git commit -m 'Update TOC'
git push
END
%x|#{command}|
end
```
See [andornaut/til](https://github.com/andornaut/til/blob/master/Rakefile) for an example.
## Development
### Installation
Requirements:
* [Bundler](https://bundler.io/)
```
# Install dependencies
$ bundle
```
### Usage
```
# List rake tasks
$ rake -T
rake build # Build mdtoc-0.0.2.gem into the pkg directory
rake default # Run the build, rubocop:auto_correct, sorbet and test tasks
rake install # Build and install mdtoc-0.0.2.gem into system gems
rake install:local # Build and install mdtoc-0.0.2.gem into system gems without...
rake release[remote] # Create tag v0.0.2 and build and push mdtoc-0.0.2.gem to ru...
rake rubocop # Run RuboCop
rake rubocop:auto_correct # Auto-correct RuboCop offenses
rake sorbet # Run the Sorbet type checker
rake test # Run tests
# Run mdtoc with test inputs
$ ruby -Ilib bin/mdtoc test/samples
# Run mdtoc with test inputs, and write to a newly created output file
$ f=$(mktemp) && ruby -Ilib bin/mdtoc -aco ${f} test/samples ; cat ${f}
```
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
0.0
Enables Type Checking per client
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024