Skip to content

Commit

Permalink
Drop deprecated ULID.valid? since #205
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick committed Aug 7, 2022
1 parent 5b4a340 commit e472b99
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 55 deletions.
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ The name of this source file (`Rakefile'`) should use snake_case.
$ ./bin/console
# Starting up IRB with loading developing ULID library
irb(main):001:0> ULID::VERSION
=> "0.7.0.pre"
=> "0.8.0.pre"
```

```ruby
Expand All @@ -47,9 +47,9 @@ ls ULID
# Module#methods: ...
# Class#methods: ...
# ULID.methods:
# at decode_time encode floor from_integer generate max min
# normalize normalized? parse parse_variant_format range sample scan try_convert
# valid? valid_as_variant_format?
# at decode_time encode floor from_integer generate max min
# normalize normalized? parse parse_variant_format range sample scan try_convert
# valid_as_variant_format?
# => nil
```

Expand Down
13 changes: 0 additions & 13 deletions lib/ulid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -321,19 +321,6 @@ def self.valid_as_variant_format?(string)
true
end

# @deprecated Use [.valid_as_variant_format?] or [.normalized?] instead
#
# Returns `true` if it is normalized string.
# Basically the difference of normalized? is to accept downcase or not. This returns true for downcased ULIDs.
#
# @return [Boolean]
def self.valid?(string)
warn_kwargs = (RUBY_VERSION >= '3.0') ? { category: :deprecated } : {}
Warning.warn('ULID.valid? is deprecated. Use ULID.valid_as_variant_format? or ULID.normalized? instead.', **warn_kwargs)
string = String.try_convert(string)
string ? STRICT_PATTERN_WITH_CROCKFORD_BASE32_SUBSET.match?(string) : false
end

# @param [ULID, #to_ulid] object
# @return [ULID, nil]
# @raise [TypeError] if `object.to_ulid` did not return ULID instance
Expand Down
13 changes: 0 additions & 13 deletions sig/ulid.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -394,19 +394,6 @@ class ULID < Object
def self.valid_as_variant_format?: (_ToStr string) -> bool
| (untyped) -> false

# DEPRECATED Use valid_as_variant_format? instead
#
# Returns `true` if it is normalized string.
# Basically the difference of normalized? is to accept downcase or not. This returns true for downcased ULIDs.
#
# ```ruby
# ULID.valid?(ULID.generate.to_s.downcase) #=> true
# ```
#
# See also [ulid/spec#57](https://github.com/ulid/spec/pull/57) and [ulid/spec#3](https://github.com/ulid/spec/issues/3)
def self.valid?: (_ToStr string) -> bool
| (untyped) -> false

# Returns parsed ULIDs from given String for rough operations.
#
# ```ruby
Expand Down
25 changes: 0 additions & 25 deletions test/core/test_ulid_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def test_exposed_methods
:scan,
:sample,
:try_convert,
:valid?, # deprecated
:max,
:min,
:generate,
Expand Down Expand Up @@ -228,30 +227,6 @@ def test_new
assert_match(/private method `new' called/, err.message)
end

def test_valid?
assert_warning('ULID.valid? is deprecated. Use ULID.valid_as_variant_format? or ULID.normalized? instead.') do
assert_false(ULID.valid?(nil))
assert_false(ULID.valid?(''))
assert_false(ULID.valid?(BasicObject.new))
assert_false(ULID.valid?(Object.new))
assert_false(ULID.valid?(42))
assert_false(ULID.valid?(:'01ARZ3NDEKTSV4RRFFQ69G5FAV'))
assert_false(ULID.valid?(ULID.sample))
assert_false(ULID.valid?("01ARZ3NDEKTSV4RRFFQ69G5FAV\n"))
assert_false(ULID.valid?('01ARZ3NDEKTSV4RRFFQ69G5FAU'))
assert_true(ULID.valid?('01ARZ3NDEKTSV4RRFFQ69G5FAV'))
assert_true(ULID.valid?('01ARZ3NDEKTSV4RRFFQ69G5FAV'.downcase))
assert_true(ULID.valid?('7ZZZZZZZZZZZZZZZZZZZZZZZZZ'))
assert_false(ULID.valid?('80000000000000000000000000'))

assert_false(ULID.valid?('01G70Y0Y7G-Z1XWDAREXERGSDDD'))
end

assert_raises(ArgumentError) do
ULID.valid?
end
end

def test_normalize
# This is the core of this feature
assert_equal(ULID.parse('01ARZ3N0EK1SV4RRFFQ61G5FAV'), ULID.parse(ULID.normalize('-OlARZ3-NoEKISV4rRFF-Q6iG5FAV--')))
Expand Down

0 comments on commit e472b99

Please sign in to comment.