Sha256: 5e4bd55b69bd6cd00b14dd8a7992f59a7a6ddce22572e5b329b4a71af3b20a55

Contents?: true

Size: 971 Bytes

Versions: 8

Compression:

Stored size: 971 Bytes

Contents

# 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
module ChangesetCallbacks

  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

  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
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
rosemary-0.2.8 lib/changeset_callbacks.rb
rosemary-0.2.7 lib/changeset_callbacks.rb
rosemary-0.2.6 lib/changeset_callbacks.rb
rosemary-0.2.5 lib/changeset_callbacks.rb
rosemary-0.2.4 lib/changeset_callbacks.rb
rosemary-0.2.3 lib/changeset_callbacks.rb
rosemary-0.2.2 lib/changeset_callbacks.rb
openstreetmap-0.2.1 lib/changeset_callbacks.rb