[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
- Fork it ( http://github.com/gzigzigzeo/format_alias/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request