Sha256: b088e09951213ae57b517a0fa6e6a72e7c1f7d7beb49717ec925480568f7987a

Contents?: true

Size: 665 Bytes

Versions: 3

Compression:

Stored size: 665 Bytes

Contents

require 'contracts'
require 'json'

module Fuselage
  module Support
    # Payload validation for Resource
    module Validation
      include ::Contracts::Core
      include ::Contracts::Builtin

      Contract String => String
      def validated(payload)
        return payload unless malformed? payload

        STDERR.puts 'Resource failed to produce valid JSON', payload
        abort
      end

      Contract String => Bool
      def valid?(payload)
        JSON.parse payload
        true
      rescue JSON::ParseError
        false
      end

      Contract String => Bool
      def malformed?(payload)
        !valid? payload
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
concourse-fuselage-0.5.8 lib/concourse-fuselage/support/validation.rb
concourse-fuselage-0.5.7 lib/concourse-fuselage/support/validation.rb
concourse-fuselage-0.5.2 lib/concourse-fuselage/support/validation.rb