Skip to content

Commit

Permalink
Allow Not(primitive_type)
Browse files Browse the repository at this point in the history
  • Loading branch information
ismasan committed Oct 2, 2024
1 parent b0fc6b2 commit 7665048
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,13 @@ NotEmail.parse('hello') # "hello"
NotEmail.parse('[email protected]') # error
```

`#not` can also be given a type as argument, which might read better:

```ruby
Types::Any.not(nil)
Types::Any.not(Types::Email)
```

#### `#options`

Sets allowed options for value.
Expand Down
4 changes: 2 additions & 2 deletions lib/plumb/not.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class Not
attr_reader :children, :errors

def initialize(step, errors: nil)
@step = step
@errors = errors
@step = Composable.wrap(step)
@errors = errors || "must not be #{step.inspect}"
@children = [step].freeze
freeze
end
Expand Down
5 changes: 5 additions & 0 deletions spec/types_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ def call(result) = result
assert_result(Types::Any.not(string).resolve('hello'), 'hello', false)

assert_result(string.not.resolve(10), 10, true)

not_nil = Types::Any.not(nil)
assert_result(not_nil.resolve(10), 10, true)
assert_result(not_nil.resolve('aa'), 'aa', true)
assert_result(not_nil.resolve(nil), nil, false)
end

specify '#invalid' do
Expand Down

0 comments on commit 7665048

Please sign in to comment.