0.0
No commit activity in last 3 years
No release in over 3 years
Provides virtual attributes to get or set certain model values (like dates) in human readable/localized format.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

[DEPRECATED] Use: https://github.com/gzigzigzeo/coerced_accessor instead

Format Alias

Provides virtual attributes to get/set certain model values in/to human readable format.

Date formatting

class Foo
  extend FormatAlias

  attr_accessor :created_at
  date_format_alias :created_at, '%d.%m.%Y'
end

bar = Foo.new
bar.created_at_formatted = '12.01.2001'
bar.created_at # => Sat, 01 Dec 2001

Accepts options:

  • :suffix - formatted by default
  • :getter_name - name of a getter method
  • :setter_name - name of a setter method (without '=')

Setting polymorphic attribute

Useful when you want to set variables from such select:

<select name="imageable">
  <option value="Image:3">Image</option>
  <option value="Banner:1">Banner</option>
  ...
</select>
class Foo < ActiveRecord::Base
  extend FormatAlias
  belongs_to :imageable
  polymorphic_alias :imageable
end

bar = Foo.new
bar.imageable_formatted = "Image:3"
bar.imageable_id   # => 3
bar.imageable_type # => "Image"

Accepts same options as #date_format_alias plus:

  • :attributes - attribute name list ([:imageable_id, :imageable_type] for the example above)

Roll your own

Installation

Add this line to your application's Gemfile:

gem 'sidekiq-batching'

And then execute:

$ bundle

Or install it yourself as:

$ gem install sidekiq-batching

Contributing

  1. Fork it ( http://github.com/gzigzigzeo/format_alias/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request