-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add Primitive::String with with smart detection for ActiveSupport and Dry inflector (And rasoable fallback) * disable lifecycle hooks * feat: automatically reject message on failures * chore(lint): fix rubocop offenses * fix: fix broken specs * feat: add back lifecycle * feat: update version to beta2
- Loading branch information
Showing
22 changed files
with
283 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: .. | ||
specs: | ||
lepus (0.0.1.beta1) | ||
lepus (0.0.1.beta2) | ||
bunny | ||
concurrent-ruby | ||
multi_json | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: .. | ||
specs: | ||
lepus (0.0.1.beta1) | ||
lepus (0.0.1.beta2) | ||
bunny | ||
concurrent-ruby | ||
multi_json | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
begin | ||
require "dry/inflector" | ||
rescue LoadError | ||
# noop | ||
end | ||
|
||
begin | ||
require "active_support/inflector" | ||
rescue LoadError | ||
# noop | ||
end | ||
|
||
module Lepus::Primitive | ||
class String < ::String | ||
def classify | ||
new_str = if defined?(Dry::Inflector) | ||
Dry::Inflector.new.classify(self) | ||
elsif defined?(ActiveSupport::Inflector) | ||
ActiveSupport::Inflector.classify(self) | ||
else | ||
split("/").collect do |c| | ||
c.split("_").collect(&:capitalize).join | ||
end.join("::") | ||
end | ||
|
||
self.class.new(new_str) | ||
end | ||
|
||
def constantize | ||
if defined?(Dry::Inflector) | ||
Dry::Inflector.new.constantize(self) | ||
elsif defined?(ActiveSupport::Inflector) | ||
ActiveSupport::Inflector.constantize(self) | ||
else | ||
Object.const_get(self) | ||
end | ||
end | ||
|
||
def underscore | ||
new_str = sub(/^::/, "") | ||
.gsub("::", "/") | ||
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') | ||
.gsub(/([a-z\d])([A-Z])/, '\1_\2') | ||
.tr("-", "_") | ||
.tr(".", "_") | ||
.gsub(/\s/, "_") | ||
.gsub(/__+/, "_") | ||
.downcase | ||
|
||
self.class.new(new_str) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.