Module: ChangesetCallbacks
- Included in:
- OpenStreetMap::Api
- Defined in:
- lib/changeset_callbacks.rb
Overview
According to the OSM API any changes made to the date need an open changeset which belongs to the user executing the changes. To keep the code simple the before_save method is included which makes sure and open
Class Method Summary collapse
Class Method Details
.before_write(klass, meth) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/changeset_callbacks.rb', line 22 def ChangesetCallbacks.before_write(klass, meth) klass.class_eval do alias_method "old_#{meth}", "#{meth}" define_method(meth) do |*args| find_or_create_open_changeset self.send("old_#{meth}", *args) end end end |
.included(into) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/changeset_callbacks.rb', line 6 def self.included(into) into.instance_methods(false).select{|method_name| [:save, :create, :update, :destroy].include?(method_name.to_sym)}.each do |m| ChangesetCallbacks.before_write(into, m) end def into.method_added(m) unless @adding @adding = true if [:save, :create, :update, :destroy].include?(m.to_sym) ChangesetCallbacks.before_write(self, m) end @adding = false end end end |