Sha256: 76ee5594336b7d1a698ca9ac40421bbcbc7ac564d8ad9e24fb71b780fbd0934d

Contents?: true

Size: 531 Bytes

Versions: 15

Compression:

Stored size: 531 Bytes

Contents

module RestfulResource
  module RailsValidations
    module ClassMethods
      def put(id, data: {}, **params)
        begin
          super(id, data: data, **params)
        rescue HttpClient::UnprocessableEntity => e
          errors = parse_json(e.response.body)
          result = data.merge(errors)
          self.new(result)
        end
      end
    end

    def self.included(base)
      base.extend(ClassMethods)
    end

    def valid?
      @inner_object.errors.nil? || @inner_object.errors.count == 0
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
restful_resource-0.8.21 lib/restful_resource/rails_validations.rb
restful_resource-0.8.20 lib/restful_resource/rails_validations.rb
restful_resource-0.8.19 lib/restful_resource/rails_validations.rb
restful_resource-0.8.18 lib/restful_resource/rails_validations.rb
restful_resource-0.8.17 lib/restful_resource/rails_validations.rb
restful_resource-0.8.16 lib/restful_resource/rails_validations.rb
restful_resource-0.8.15 lib/restful_resource/rails_validations.rb
restful_resource-0.8.14 lib/restful_resource/rails_validations.rb
restful_resource-0.8.13 lib/restful_resource/rails_validations.rb
restful_resource-0.8.12 lib/restful_resource/rails_validations.rb
restful_resource-0.8.11 lib/restful_resource/rails_validations.rb
restful_resource-0.8.10 lib/restful_resource/rails_validations.rb
restful_resource-0.8.9 lib/restful_resource/rails_validations.rb
restful_resource-0.8.8 lib/restful_resource/rails_validations.rb
restful_resource-0.8.7 lib/restful_resource/rails_validations.rb