Skip to content
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
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Revision history for Red
- Track in-place mutations of Positional, Associative and Json columns when saving.
- Snapshot mutable collection values deeply and retain independent old values for dirty tracking.
- Refresh snapshots on clean-up and partial refresh without marking unchanged collections dirty.
- Return explicitly bound drivers directly and replace literal name separators without regex matching.
- Retain formatter coercions, repeated separators, Unicode and embedded control characters.
- schema: add named CHECK and PostgreSQL EXCLUDE constraints with driver selection
- indexes: support access methods, per-key operator classes and partial predicates
- pg: add range constructors and native range/regex expression helpers
Expand Down
5 changes: 2 additions & 3 deletions lib/Red/DB.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ use X::Red::Exceptions;

#| Returns the database connection
sub get-RED-DB is export {
with $*RED-DB {
.return
}
my $driver = $*RED-DB;
return $driver if $driver.defined;
if %*RED-DEFAULT-DRIVERS.defined and %*RED-DEFAULT-DRIVERS<default>:exists {
return %*RED-DEFAULT-DRIVERS<default>
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Red/Utils.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use Red::AST::Unary;
=head2 Red::Utils

#| Accepts a string and converts snake case (`foo_bar`) into kebab case (`foo-bar`).
sub snake-to-kebab-case(Str() $_ --> Str) is export { S:g/'_'/-/ }
sub snake-to-kebab-case(Str() $_ --> Str) is export { .subst('_', '-', :g) }
#| Accepts a string and converts kebab case (`foo-bar`) into snake case (`foo_bar`).
sub kebab-to-snake-case(Str() $_ --> Str) is export { S:g/'-'/_/ }
sub kebab-to-snake-case(Str() $_ --> Str) is export { .subst('-', '_', :g) }
#| Accepts a string and converts camel case (`fooBar`) into snake case (`foo_bar`).
sub camel-to-snake-case(Str() $_ --> Str) is export { kebab-to-snake-case lc S:g/(\w)<?before <[A..Z]>>/$0_/ }
#| Accepts a string and converts camel case (`fooBar`) into kebab case (`foo-bar`).
Expand All @@ -26,4 +26,4 @@ multi compare(Red::AST::So $a, Red::AST $b) {

multi compare(Red::AST $a, Red::AST::So $b) {
compare $a, $b.value
}
}
14 changes: 14 additions & 0 deletions t/104-name-formatters.rakutest
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use Test;
use Red::Utils;

for ['plain', 'plain'], ['a-b-c', 'a_b_c'], ['--a--', '__a__'], ['', ''],
['ação-número', 'ação_número'], ["a\n-\0b", "a\n_\0b"] -> @pair {
is kebab-to-snake-case(@pair[0]), @pair[1], 'Format kebab separators';
is snake-to-kebab-case(@pair[1]), @pair[0], 'Format snake separators';
}
is kebab-to-snake-case('already_snake'), 'already_snake', 'Keep existing underscores';
is snake-to-kebab-case('already-kebab'), 'already-kebab', 'Keep existing hyphens';
is kebab-to-snake-case(42), '42', 'Kebab formatter retains Str coercion';
is snake-to-kebab-case(42), '42', 'Snake formatter retains Str coercion';

done-testing;
Loading