Module: PactBroker::Api::Contracts::ValidationHelpers
- Extended by:
- ValidationHelpers
- Included in:
- ValidationHelpers, WebhookRequestContract
- Defined in:
- lib/pact_broker/api/contracts/validation_helpers.rb
Instance Method Summary collapse
-
#blank?(value) ⇒ Boolean
True if there is a value present, and it only contains whitespace.
- #environment_with_name_exists?(value) ⇒ Boolean
- #includes_space?(value) ⇒ Boolean
- #multiple_lines?(value) ⇒ Boolean
- #not_provided?(value) ⇒ Boolean
- #pacticipant_with_name_exists?(value) ⇒ Boolean
-
#provided?(value) ⇒ Boolean
The tins gem has screwed up the present? method by not using refinements Return true if the object is not nil, and if a String, is not blank.
- #valid_http_method?(http_method) ⇒ Boolean
- #valid_url?(url) ⇒ Boolean
- #valid_version_number?(value) ⇒ Boolean
Instance Method Details
#blank?(value) ⇒ Boolean
Returns true if there is a value present, and it only contains whitespace.
22 23 24 |
# File 'lib/pact_broker/api/contracts/validation_helpers.rb', line 22 def blank?(value) value&.blank? end |
#environment_with_name_exists?(value) ⇒ Boolean
57 58 59 |
# File 'lib/pact_broker/api/contracts/validation_helpers.rb', line 57 def environment_with_name_exists?(value) PactBroker::Services.environment_service.find_by_name(value) end |
#includes_space?(value) ⇒ Boolean
17 18 19 |
# File 'lib/pact_broker/api/contracts/validation_helpers.rb', line 17 def includes_space?(value) value && value.is_a?(String) && value.include?(" ") end |
#multiple_lines?(value) ⇒ Boolean
13 14 15 |
# File 'lib/pact_broker/api/contracts/validation_helpers.rb', line 13 def multiple_lines?(value) value && value.is_a?(String) && value.include?("\n") end |
#not_provided?(value) ⇒ Boolean
37 38 39 |
# File 'lib/pact_broker/api/contracts/validation_helpers.rb', line 37 def not_provided?(value) !provided?(value) end |
#pacticipant_with_name_exists?(value) ⇒ Boolean
53 54 55 |
# File 'lib/pact_broker/api/contracts/validation_helpers.rb', line 53 def pacticipant_with_name_exists?(value) PactBroker::Services.pacticipant_service.find_pacticipant_by_name(value) end |
#provided?(value) ⇒ Boolean
The tins gem has screwed up the present? method by not using refinements Return true if the object is not nil, and if a String, is not blank.
29 30 31 32 33 34 35 |
# File 'lib/pact_broker/api/contracts/validation_helpers.rb', line 29 def provided?(value) if value.is_a?(String) value.strip.size > 0 else !value.nil? end end |
#valid_http_method?(http_method) ⇒ Boolean
47 48 49 50 51 |
# File 'lib/pact_broker/api/contracts/validation_helpers.rb', line 47 def valid_http_method?(http_method) Net::HTTP.const_defined?(http_method.capitalize) rescue StandardError false end |
#valid_url?(url) ⇒ Boolean
41 42 43 44 45 |
# File 'lib/pact_broker/api/contracts/validation_helpers.rb', line 41 def valid_url?(url) URI(url) rescue URI::InvalidURIError, ArgumentError false end |
#valid_version_number?(value) ⇒ Boolean
61 62 63 64 65 66 67 |
# File 'lib/pact_broker/api/contracts/validation_helpers.rb', line 61 def valid_version_number?(value) if PactBroker.configuration.order_versions_by_date true else !!PactBroker.configuration.version_parser.call(value) end end |