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 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
Custom form field_tag of range-slider with text_field type selector. You can either choose from drop down or enter your own value and the slider will auto-adjust or you can use the slider to adjust values. This all through on form field f.slide_selector. Check out https://github.com/Touqeer-tqr/custom-form for sample app
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2.91
Sorbet's runtime type checking component
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
Activity
0.0
Guard plugin for the Sorbet Ruby type checker
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
Activity
0.2
A type coercion lib works with Sorbet's static type checker and type definitions; raises an error if the coercion fails.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
Activity
0.0
# Rake::ToolkitProgram
Create toolkit programs easily with `Rake` and `OptionParser` syntax. Bash completions and usage help are baked in.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'rake-toolkit_program'
```
And then execute:
$ bundle
Or install it yourself as:
$ gem install rake-toolkit_program
## Quickstart
* Shebang it up (in a file named `awesome_tool.rb`)
```ruby
#!/usr/bin/env ruby
```
* Require the library
```ruby
require 'rake/toolkit_program'
```
* Make your life easier
```ruby
Program = Rake::ToolkitProgram
```
* Define your command tasks
```ruby
Program.command_tasks do
desc "Build it"
task 'build' do
# Ruby code here
end
desc "Test it"
task 'test' => ['build'] do
# Rake syntax ↑↑↑↑↑↑↑ for dependencies
# Ruby code here
end
end
```
You can use `Program.args` in your tasks to access the other arguments on the command line. For argument parsing integrated into the help provided by the program, see the use of `Rake::Task(Rake::ToolkitProgram::TaskExt)#parse_args` below.
* Wire the mainline
```ruby
Program.run(on_error: :exit_program!) if $0 == __FILE__
```
* In the shell, prepare to run the program (UNIX/Linux systems only)
```console
$ chmod +x awesome_tool.rb
$ ./awesome_tool.rb --install-completions
Completions installed in /home/rtweeks/.bashrc
Source /home/rtweeks/.bash-complete/awesome_tool.rb-completions for immediate availability.
$ source /home/rtweeks/.bash-complete/awesome_tool.rb-completions
```
* Ask for help
```console
$ ./awesome_tool.rb help
*** ./awesome_tool.rb Toolkit Program ***
.
.
.
```
## Usage
Let's look at a short sample toolkit program -- put this in `awesome.rb`:
```ruby
#!/usr/bin/env ruby
require 'rake/toolkit_program'
require 'ostruct'
ToolkitProgram = Rake::ToolkitProgram
ToolkitProgram.title = "My Awesome Toolkit of Awesome"
ToolkitProgram.command_tasks do
desc <<-END_DESC.dedent
Fooing myself
I'm not sure what I'm doing, but I'm definitely fooing!
END_DESC
task :foo do
a = ToolkitProgram.args
puts "I'm fooed#{' on a ' if a.implement}#{a.implement}"
end.parse_args(into: OpenStruct.new) do |parser, args|
parser.no_positional_args!
parser.on('-i', '--implement IMPLEMENT', 'An implement on which to be fooed') do |val|
args.implement = val
end
end
end
if __FILE__ == $0
ToolkitProgram.run(on_error: :exit_program!)
end
```
Make sure to `chmod +x awesome.rb`!
What does this support?
$ ./awesome.rb foo
I'm fooed
$ ./awesome.rb --help
*** My Awesome Toolkit of Awesome ***
Usage: ./awesome.rb COMMAND [OPTION ...]
Avaliable options vary depending on the command given. For details
of a particular command, use:
./awesome.rb help COMMAND
Commands:
foo Fooing myself
help Show a list of commands or details of one command
Use help COMMAND to get more help on a specific command.
$ ./awesome.rb help foo
*** My Awesome Toolkit of Awesome ***
Usage: ./awesome.rb foo [OPTION ...]
Fooing myself
I'm not sure what I'm doing, but I'm definitely fooing!
Options:
-i, --implement IMPLEMENT An implement on which to be fooed
$ ./awesome.rb --install-completions
Completions installed in /home/rtweeks/.bashrc
Source /home/rtweeks/.bash-complete/awesome.rb-completions for immediate availability.
$ source /home/rtweeks/.bash-complete/awesome.rb-completions
$ ./awesome.rb <tab><tab>
foo help
$ ./awesome.rb f<tab>
↳ ./awesome.rb foo
$ ./awesome.rb foo <tab>
↳ ./awesome.rb foo --
$ ./awesome.rb foo --<tab><tab>
--help --implement
$ ./awesome.rb foo --i<tab>
↳ ./awesome.rb foo --implement
$ ./awesome.rb foo --implement <tab><tab>
--help awesome.rb
$ ./awesome.rb foo --implement spoon
I'm fooed on a spoon
### Defining Toolkit Commands
Just define tasks in the block of `Rake::ToolkitProgram.command_tasks` with `task` (i.e. `Rake::DSL#task`). If `desc` is used to provide a description, the task will become visible in help and completions.
When a command task is initially defined, positional arguments to the command are available as an `Array` through `Rake::ToolkitProgram.args`.
### Option Parsing
This gem extends `Rake::Task` with a `#parse_args` method that creates a `Rake::ToolkitProgram::CommandOptionParser` (derived from the standard library's `OptionParser`) and an argument accumulator and `yield`s them to its block.
* The arguments accumulated through the `Rake::ToolkitProgram::CommandOptionParser` are available to the task in `Rake::ToolkitProgram.args`, replacing the normal `Array` of positional arguments.
* Use the `into:` keyword of `#parse_args` to provide a custom argument accumulator object for the associated command. The default argument accumulator constructor can be defined with `Rake::ToolkitProgram.default_parsed_args`. Without either of these, the default accumulator is a `Hash`.
* Options defined using `OptionParser#on` (or any of the variants) will print in the help for the associated command.
### Positional Arguments
Accessing positional arguments given after the command name depends on whether or not `Rake::Task(Rake::ToolkitProgram::TaskExt)#parse_args` has been called on the command task. If this method is not called, positional arguments will be an `Array` accessible through `Rake::ToolkitProgram.args`.
When `Rake::Task(Rake::ToolkitProgram::TaskExt)#parse_args` is used:
* `Rake::ToolkitProgram::CommandOptionParser#capture_positionals` can be used to define how positional arguments are accumulated.
* If the argument accumulator is a `Hash`, the default (without calling this method) is to assign the `Array` of positional arguments to the `nil` key of the `Hash`.
* For other types of accumulators, the positional arguments are only accessible if `Rake::ToolkitProgram::CommandOptionParser#capture_positionals` is used to define how they are captured.
* If a block is given to this method, the block of the method will receive the `Array` of positional arguments. If it is passed an argument value, that value is used as the key under which to store the positional arguments if the argument accumulator is a `Hash`.
* `Rake::ToolkitProgram::CommandOptionParser#expect_positional_cardinality` can be used to set a rule for the count of positional arguments. This will affect the _usage_ presented in the help for the associated command.
* `Rake::ToolkitProgram::CommandOptionParser#map_positional_args` may be used to transform (or otherwise process) positional arguments one at a time and in the context of options and/or arguments appearing earlier on the command line.
### Convenience Methods
* `Rake::Task(Rake::ToolkitProgram::TaskExt)#prohibit_args` is a quick way, for commands that accept no options or positional arguments, to declare this so the help and bash completions reflect this. It is equivalent to using `#parse_args` and telling the parser `parser.expect_positional_cardinality(0)`.
* `Rake::ToolkitProgram::CommandOptionParser#no_positional_args!` is a shortcut for calling `#expect_positional_cardinality(0)` on the same object.
* `Rake::Task(Rake::ToolkitProgram::TaskExt)#invalid_args!` and `Rake::ToolkitProgram::CommandOptionParser#invalid_args!` are convenient ways to raise `Rake::ToolkitProgram::InvalidCommandLine` with a message.
## OptionParser in Rubies Before and After v2.4
The `OptionParser` class was extended in Ruby 2.4 to simplify capturing options into a `Hash` or other container implementing `#[]=` in a similar way. This gem supports that, but it means that behavior varies somewhat between the pre-2.4 era and the 2.4+ era. To have consistent behavior across that version change, the recommendation is to use a `Struct`, `OpenStruct`, or custom class to hold program options rather than `Hash`.
## Development
After checking out the repo, run `bin/setup` to install dependencies. 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).
To run the tests, use `rake`, `rake test`, or `rspec spec`. Tests can only be run on systems that support `Kernel#fork`, as this is used to present a pristine and isolated environment for setting up the tool. If run using Ruby 2.3 or earlier, some tests will be pending because functionality expects Ruby 2.4's `OptionParser`.
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/PayTrace/rake-toolkit_program. For further details on contributing, see [CONTRIBUTING.md](./CONTRIBUTING.md).
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
0.0
A puppet-lint plugin to check if parameters in Classes and Defines has types declared.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
0.0
A collection of diverse simple utilities without much anything to do
with one another. The main rationale is to reduce the time spent on
boilerplate like checking whether the arguments have the right type,
or introducing some basic internationalization. More detail in the README.
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
"Pokemoves allows you to easily check which moves pokemon can learn, as well as which pokemon can learn a specific move. You can also check a move's given type."
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
Activity
0.01
Run-time type checker and transformer 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
TStruct is type checked Struct
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
0.0
Type Checker for Ruby at runtime using YARD
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.01
A dynamic type checker for gRPC methods
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
Activity
0.0
A rich language which compiles to ruby. Including type annotations, type checking, macros, annotations, enums and more
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
Activity
0.01
A puppet-lint plugin to check that Optional class/defined type parameters don't default to anything other than `undef`.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
Activity
0.0
Allows you check if an object match a class expression. It is typically
used to check the type of method paraameters. It is an alternative to using
Ruby-3 .rbs files but with a different syntax and only dynamic checks
Typically you'll include the Constrain module and use #constrain to check
the type of method parameters:
include Constrain
# f takes a String and an array of Integer objects. Raise a Constrain::Error
# if parameters doesn't have the expected types
def f(a, b)
constrain a, String
constrain b, [Integer]
end
Constrain works with ruby-2 (and maybe ruby-3)
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
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
Activity