Module: ExpoTurbo::Rails::RegistryIdentifier
- Defined in:
- lib/expo_turbo/rails/registry_identifier.rb
Class Method Summary collapse
- .noncharacter?(codepoint) ⇒ Boolean
- .valid?(value) ⇒ Boolean
- .validate!(value, field_path, error_class: ConfigurationError) ⇒ Object
Class Method Details
.noncharacter?(codepoint) ⇒ Boolean
34 35 36 37 |
# File 'lib/expo_turbo/rails/registry_identifier.rb', line 34 def noncharacter?(codepoint) codepoint.between?(0xFDD0, 0xFDEF) || (codepoint <= 0x10FFFF && [0xFFFE, 0xFFFF].include?(codepoint & 0xFFFF)) end |
.valid?(value) ⇒ Boolean
27 28 29 30 31 32 |
# File 'lib/expo_turbo/rails/registry_identifier.rb', line 27 def valid?(value) validate!(value, "value") true rescue ConfigurationError false end |
.validate!(value, field_path, error_class: ConfigurationError) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/expo_turbo/rails/registry_identifier.rb', line 8 def validate!(value, field_path, error_class: ConfigurationError) unless value.is_a?(String) raise error_class, "Expo Turbo registry identifier #{field_path} must be a String, got #{value.class}" end unless value.valid_encoding? raise error_class, "Expo Turbo registry identifier #{field_path} is not valid UTF-8" end value.each_codepoint.with_index do |codepoint, scalar_index| next unless noncharacter?(codepoint) formatted = codepoint.to_s(16).upcase.rjust(4, "0") raise error_class, "Expo Turbo registry identifier #{field_path} contains Unicode noncharacter U+#{formatted} at scalar index #{scalar_index}" end value end |