lib/rgeoserver/resource.rb in rgeoserver-0.5.6 vs lib/rgeoserver/resource.rb in rgeoserver-0.5.7

- old
+ new

@@ -53,27 +53,47 @@ end def to_s "#{self.class.name}: #{name}" end + + # Return full name of resource with namespace prefix + def prefixed_name + return "#{workspace.name}:#{name}" if self.respond_to?(:workspace) + raise "Workspace is not defined for this resource" + end def create_method :post end def update_method :put end + + # We pass the old name "name_route" in case the name of the resource is being edited + # Child classes should implement this + def update_params name_route = name + { self.class.resource_name.downcase.to_sym => name_route } + end # Modify or save the resource # @param [Hash] options / query parameters # @return [RGeoServer::ResourceInfo] def save options = {} @previously_changed = changes @changed_attributes.clear run_callbacks :save do - if new? + unless @previously_changed[:name].nil? + old_name, new_name = @previously_changed[:name] + name_route = old_name if old_name != new_name + update = true + else + name_route = name + update = false + end + if !update && new? if self.respond_to?(:create_route) raise "Resource cannot be created directly" if create_route.nil? route = create_route else route = {@route => nil} @@ -81,11 +101,11 @@ options = create_options.merge(options) if self.respond_to?(:create_options) @catalog.add(route, message, create_method, options) clear else - options = update_options.merge(options) if self.respond_to?(:update_options) - route = self.respond_to?(:update_route)? update_route : {@route => @name} + options = update_params(name_route).merge(options) + route = {@route => name_route} @catalog.modify(route, message, update_method, options) #unless changes.empty? end self end