No commit activity in last 3 years
No release in over 3 years
Integrate template_params with rails
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.12
~> 10.0
~> 3.4

Runtime

< 5.2, >= 4.1.0
 Project Readme

TemplateParamsRails

Runtime type-check for template preconditions, including instance variables and local variables. Think of this as the method signature of a template. There should be at least one of these assertions in almost every template.

template_params-rails project integrates template_params for rails.

Installation

Add this line to your application's Gemfile:

gem 'template_params-rails'

And then execute:

$ bundle

Or install it yourself as:

$ gem install template_params-rails

Usage

In template, you may want to use template_param like this:

# Assert `poll` is defined. If not, raises an `ArgumentError` (the "arguments"
# of the template are invalid).
template_param { poll }

# Assert `@course` is defined. Meaningless because instance variables are
# always defined.
template_param { @course }

# Assert `poll.is_a?(::Poll)`. If not, raises a `TypeError`.
template_param(::Poll) { poll }

# Assert `@course.is_a?(::Course)`
template_param(::Course) { @course }

# Assert `@course` is either a `::Course` or `nil`
template_param(::Course, allow_nil: true) { @course }

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/opodartho/template_params-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.