Module: TinySweeper::ClassMethods
- Defined in:
- lib/tiny_sweeper.rb
Instance Method Summary collapse
Instance Method Details
#sweep(field_name, &sweeper) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/tiny_sweeper.rb', line 3 def sweep(field_name, &sweeper) stop_if_attribute_does_not_exist!(field_name) stop_if_we_have_seen_this_before!(field_name) writer_method_name = writer_method_name(field_name) alias_method "original #{writer_method_name}", writer_method_name define_method(writer_method_name) do |value| clean_value = sweeper.call(value) send("original #{writer_method_name}", clean_value) end end |
#sweep_up!(instance) ⇒ Object
17 18 19 20 21 |
# File 'lib/tiny_sweeper.rb', line 17 def sweep_up!(instance) @swept_fields.each do |field| instance.send("#{field}=", instance.send(field)) end end |