Module: Blobby::KeyConstraint
- Defined in:
- lib/blobby/key_constraint.rb
Overview
Defines the keys we allow for use in BLOB-store implementations.
Basically, we allow anything that would be a valid URI “path” component.
Constant Summary collapse
- BAD_PATTERNS =
[ %r{\A\Z}, # blank %r{\A/}, # leading slash %r{/\Z}, # trailing slash %r{//+}, # multiple slashes %r{:} # colon ].freeze
Class Method Summary collapse
Class Method Details
.allows?(key) ⇒ Boolean
23 24 25 26 27 28 |
# File 'lib/blobby/key_constraint.rb', line 23 def allows?(key) BAD_PATTERNS.none? { |pattern| pattern =~ key } && URI.parse(key).path == key rescue URI::InvalidURIError false end |
.must_allow!(key) ⇒ Object
30 31 32 |
# File 'lib/blobby/key_constraint.rb', line 30 def must_allow!(key) fail ArgumentError, "invalid key: #{key.inspect}" unless allows?(key) end |