Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix documentation #113

Merged
merged 3 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docsite/source/builder.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ layout: gem-single
name: dry-logic
---

Use Dry Logic's builder evaluate predicates and operations
Use Dry Logic's builder to evaluate predicates and operations.

``` ruby
require "dry/logic/builder"

is_zero = Dry::Logic::Builder.call do
lt?(0) ^ gt?(0)
lteq?(0) & gteq?(0)
end

is_zero.call(0).success? # => true
Expand Down
16 changes: 8 additions & 8 deletions docsite/source/operations.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ end

is_number.call(1).success? # => true
is_number.call(2.0).success? # => true
is_number.call('3').success? # => false
is_number.call('3').success? # => true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch, it wasn't obvious number? has coercion inside

is_number.call('four').success? # => false
```

Expand Down Expand Up @@ -98,9 +98,9 @@ is_middle_aged = build do
gt?(30) & lt?(50)
end

is_child.call(20).success? # => false
is_child.call(40).success? # => true
is_child.call(60).success? # => true
is_middle_aged.call(20).success? # => false
is_middle_aged.call(40).success? # => true
is_middle_aged.call(60).success? # => false
```

### Attribute (`attr`)
Expand Down Expand Up @@ -138,10 +138,10 @@ is_only_odd.call([4, 6, 8]).success? # => false

``` ruby
is_natural_and_odd = build do
set(int?, odd?, gt?(1))
set { [int?, odd?, gt?(1)] }
end

is_natural_and_odd.call('5').success? # => false
is_natural_and_odd.call('5').success? # => NoMethodError: undefined method `odd?' for "5":String
is_natural_and_odd.call(5).success? # => true
is_natural_and_odd.call(-1).success? # => false
```
Expand All @@ -152,7 +152,7 @@ is_natural_and_odd.call(-1).success? # => false

``` ruby
is_present = build do
negation(empty?)
negation { empty? }
end

is_present.call([1]).success? # => true
Expand All @@ -166,7 +166,7 @@ is_present.call("").success? # => false
``` ruby
is_named = build do
key name: [:user, :name] do
str? & negation(empty?)
str? & negation { empty? }
end
end

Expand Down
18 changes: 9 additions & 9 deletions docsite/source/predicates.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Predicates can be chained together using operations such as `&` and `|` (see the
is_https_url = build { uri?(:https) }
is_https_url = build { uri?(/https?/) }
is_http_url = build { uri?(:http) }
is_url = build { uri?([:http, :https]) }
is_url = build { uri?(['http', 'https']) }

https_url = "https://example.com"
http_url = "http://example.com"
Expand All @@ -23,7 +23,7 @@ local_url = "example.local"
is_https_url.call(https_url).success? # => true
is_https_url.call(local_url).success? # => false
is_http_url.call(http_url).success? # => true
is_url.call(https_url).success? # => false
is_url.call(https_url).success? # => true
```

### UUID (`uuid_v1?`, `uuid_v2?`, `uuid_v3?`, `uuid_v4?`, `uuid_v5?`)
Expand Down Expand Up @@ -384,15 +384,15 @@ is_float.call(1.0).success? # => true
is_float.call(1).success? # => false
```

### Number (`num?`)
### Integer (`int?`)

> Returns true if the input is of type `Integer`

``` ruby
is_num = build { num? }
is_int = build { int? }

is_num.call(1).success? # => true
is_num.call(1.0).success? # => false
is_int.call(1).success? # => true
is_int.call(1.0).success? # => false
```

### Time (`time?`)
Expand Down Expand Up @@ -453,7 +453,7 @@ is_false = build { false? }
is_true.call(true).success? # => true
is_true.call(false).success? # => false
is_false.call(false).success? # => true
is_true.call(true).success? # => false
is_false.call(true).success? # => false
```

### Empty (`empty?`)
Expand Down Expand Up @@ -540,6 +540,6 @@ is_named.call({ age: 30 }).success? # => false
``` ruby
is_email_ish = build { format?(/^\S+@\S+$/) }

is_email_ish.call("[email protected]") # => true
is_email_ish.call("nope|failed.com") # => false
is_email_ish.call("[email protected]").success? # => true
is_email_ish.call("nope|failed.com").success? # => false
```
Loading