Sha256: 6a464308d76f4b676113a9e57b73fe9de39cb3501321a41b19d27424f4c6a9f2

Contents?: true

Size: 915 Bytes

Versions: 20

Compression:

Stored size: 915 Bytes

Contents

# encoding: utf-8

module Nimbu
  module Request
    module Validations
      # A mixin to help validate presence of non-empty values
      module Presence

        # Ensure that esential arguments are present before request is made.
        #
        # == Parameters
        #  Hash/Array of arguments to be checked against nil and empty string
        #
        # == Example
        #  assert_presence_of user: '...', repo: '...'
        #  assert_presence_of user, repo
        #
        def assert_presence_of(*args)
          hash = args.last.is_a?(::Hash) ? args.pop : {}

          errors = hash.select { |key, val| val.to_s.empty? }
          raise Nimbu::Error::Validations.new(errors) unless errors.empty?

          args.each do |arg|
            raise ArgumentError, "parameter cannot be nil" if arg.nil?
          end
        end

      end # Presence
    end # Validations
  end # Request
end # Nimbu

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
nimbu-api-0.5.0 lib/nimbu-api/request/validations/presence.rb
nimbu-api-0.4.4 lib/nimbu-api/request/validations/presence.rb
nimbu-api-0.4.3 lib/nimbu-api/request/validations/presence.rb
nimbu-api-0.4.2 lib/nimbu-api/request/validations/presence.rb
nimbu-api-0.4.1 lib/nimbu-api/request/validations/presence.rb
nimbu-api-0.4.0 lib/nimbu-api/request/validations/presence.rb
nimbu-api-0.3.0 lib/nimbu-api/request/validations/presence.rb
nimbu-api-0.2.1 lib/nimbu-api/request/validations/presence.rb
nimbu-api-0.2 lib/nimbu-api/request/validations/presence.rb
nimbu-api-0.2.beta.3 lib/nimbu-api/request/validations/presence.rb
nimbu-api-0.2.beta.2 lib/nimbu-api/request/validations/presence.rb
nimbu-api-0.2.beta.1 lib/nimbu-api/request/validations/presence.rb
nimbu-api-0.2.beta lib/nimbu-api/request/validations/presence.rb
nimbu-api-0.1.5 lib/nimbu-api/request/validations/presence.rb
nimbu-api-0.1.4 lib/nimbu-api/request/validations/presence.rb
nimbu-api-0.1.3 lib/nimbu-api/request/validations/presence.rb
nimbu-api-0.1.1 lib/nimbu-api/request/validations/presence.rb
nimbu-api-0.1 lib/nimbu-api/request/validations/presence.rb
nimbu-api-0.0.2 lib/nimbu-api/request/validations/presence.rb
nimbu-api-0.0.1 lib/nimbu-api/request/validations/presence.rb