Sha256: a0fd836720efe6f002ddad8a2624443ef78056fa7ac525d8243d351b92d1734b

Contents?: true

Size: 1.11 KB

Versions: 21

Compression:

Stored size: 1.11 KB

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 = nil
          if errors.is_a?(Hash) && errors.has_key?('errors')
            result = data.merge(errors)
          else
            result = data.merge(errors: errors)
          end
          result = result.merge(id: id)
          self.new(result)
        end
      end

      def post(data: {}, **params)
        begin
          super(data: data, **params)
        rescue HttpClient::UnprocessableEntity => e
          errors = parse_json(e.response.body)
          result = nil
          if errors.is_a?(Hash) && errors.has_key?('errors')
            result = data.merge(errors)
          else
            result = data.merge(errors: errors)
          end
          self.new(result)
        end
      end
    end

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

    def valid?
      @inner_object.errors.nil?
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
restful_resource-1.3.0 lib/restful_resource/rails_validations.rb
restful_resource-1.2.2 lib/restful_resource/rails_validations.rb
restful_resource-1.2.1 lib/restful_resource/rails_validations.rb
restful_resource-1.2.0 lib/restful_resource/rails_validations.rb
restful_resource-1.1.0 lib/restful_resource/rails_validations.rb
restful_resource-1.0.0 lib/restful_resource/rails_validations.rb
restful_resource-0.10.2 lib/restful_resource/rails_validations.rb
restful_resource-0.10.1 lib/restful_resource/rails_validations.rb
restful_resource-0.10.0 lib/restful_resource/rails_validations.rb
restful_resource-0.9.7 lib/restful_resource/rails_validations.rb
restful_resource-0.9.5 lib/restful_resource/rails_validations.rb
restful_resource-0.9.4 lib/restful_resource/rails_validations.rb
restful_resource-0.9.3 lib/restful_resource/rails_validations.rb
restful_resource-0.9.2 lib/restful_resource/rails_validations.rb
restful_resource-0.9.1 lib/restful_resource/rails_validations.rb
restful_resource-0.9.0 lib/restful_resource/rails_validations.rb
restful_resource-0.8.34 lib/restful_resource/rails_validations.rb
restful_resource-0.8.33 lib/restful_resource/rails_validations.rb
restful_resource-0.8.32 lib/restful_resource/rails_validations.rb
restful_resource-0.8.30 lib/restful_resource/rails_validations.rb