lib/ncmb/object.rb in ncmb-ruby-client-0.1.3 vs lib/ncmb/object.rb in ncmb-ruby-client-0.1.4

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + module NCMB class Object include NCMB def initialize(name, fields = {}) @@ -62,16 +64,16 @@ def saved? @fields[:objectId] != nil end - def post + def convert_params @fields.each do |key, field| if field.is_a?(NCMB::Object) field.save unless field.saved? @fields[key] = { - __type: "Pointer", + __type: 'Pointer', className: field.ClassName, objectId: field.objectId } end if field.is_a?(Array) && field[0].is_a?(NCMB::Object) @@ -81,16 +83,23 @@ relation << sub_field end @fields[key] = relation end end + end + + def post + return self.put if saved? + convert_params result = @@client.post path, @fields @fields.merge!(result) self end alias :save :post def put + return self.post unless saved? + convert_params put_path = path params = @fields params.delete :objectId params.delete :createDate params.delete :updateDate