Project

tuning

0.0
No commit activity in last 3 years
No release in over 3 years
Common tools used in rails extracted into a gem.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
 Dependencies

Development

~> 1.2
~> 0.21

Runtime

~> 5.1
 Project Readme

Gem Version Code Climate Build Status Dependency Status

Tuning

Common tools used in rails extracted into a gem.

Why

I did this gem to:

  • Make features I commonly need work nice together.
  • Have an extensible container to continue adding new general purpose tools.

Install

Put this line in your Gemfile:

gem 'tuning'

Then bundle:

$ bundle

Usage

Mailers

Text email templates will normalize spaces and new lines like html:

<% if @order.confirmed? %>
  Your order has been confirmed.

  Will be delivered right the way.
<% end %>

Will produce:

Your order has been confirmed.

Will be delivered right the way.

Views

New content_tag_if method to wrap content into some tag if certain condition it's true:

<%= content_tag_if request.path == home_path, :h1 do %>
  <%= link_to 'Home', home_path, id: 'logo' %>
<% end %>

New active_trail? method to check if some path is on active trail:

<li class="<%= 'active' if active_trail? some_path %>"></li>

New extending method to extend layouts:

<%= extending :application do %>
  <p>content</p>
<% end %>

Template Handlers

Ruby template handlers will automatically call to_json:

@users.map do |user|
  user.slice :name
end

Records

Empty strings will be nilify in the database to avoid sql errors or complex queries:

shop = Shop.new(name: '')
shop.save
shop.name # Will be nil

New method validate is available to allow a more expressive syntax:

record.validate

Validations

New complexity validator to avoid weak passwords:

class User < ActiveRecord::Base
  validates_complexity_of :password
end

New time validator to validate Date/Time using after, after_or_equal_to, before or before_or_equal_to:

class Schedule < ActiveRecord::Base
  validates_time_of :opens_at
  validates_time_of :closes_at, after: :opens_at
end

New count validator to express count messages using minimum, maximum, in o within:

class Product < ActiveRecord::Base
  validates_count_of :pictures, minimum: 1, maximum: 4
end

NOTE: Take a look at lib/tuning/locales to know the i18n keys.

Contributing

Any issue, pull request, comment of any kind is more than welcome!

I will mainly ensure compatibility to Rails, AWS, PostgreSQL, Redis, Elasticsearch and FreeBSDĀ 

Credits

This gem is maintained and funded by museways.

License

It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.