Sha256: ca2df2638980cc2b183d728ed39827dc7608da26f929fa851f1fd11e50183d69
Contents?: true
Size: 562 Bytes
Versions: 2
Compression:
Stored size: 562 Bytes
Contents
require "transformable/version" module Transformable def self.included(base) base.extend ClassMethods end module ClassMethods def clean(attr, options={}, &blk) skip_nil = options.fetch(:skip_nil) { true } define_method "#{attr}=" do |value| if value.nil? and skip_nil new_value = value else new_value = yield(value) end instance_variable_set("@#{attr}", new_value) write_attribute(attr, new_value) if defined? ActiveRecord and defined? ActiveRecord::Base and is_a? ActiveRecord::Base end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
transformable-1.0.0 | lib/transformable.rb |
transformable-0.0.5 | lib/transformable.rb |