Hook called when module is extended
Add encoding DSL method to descendant and set the default to UTF-8.
@param [Class<Axiom::Types::Type>] descendant
@return [undefined]
@api private
# File lib/axiom/types/encodable.rb, line 21 def self.extended(descendant) super descendant.accept_options :encoding descendant.encoding Encoding::UTF_8 end
Finalize by setting up a primitive constraint
@return [Axiom::Types::Encodable]
@api private
# File lib/axiom/types/encodable.rb, line 34 def finalize return self if frozen? ascii_compatible? ? has_ascii_compatible_encoding : has_encoding super end
Test if the encoding is ascii compatible
@return [Boolean]
@api private
# File lib/axiom/types/encodable.rb, line 47 def ascii_compatible? encoding.ascii_compatible? end
Add constraint for the ascii compatible encoding
@return [undefined]
@api private
# File lib/axiom/types/encodable.rb, line 56 def has_ascii_compatible_encoding constraint do |object| object.encoding.equal?(encoding) || object.to_s.ascii_only? end end
Add constraint for the encoding
@return [undefined]
@api private
# File lib/axiom/types/encodable.rb, line 67 def has_encoding constraint { |object| object.encoding.equal?(encoding) } end