Skip to content

Commit

Permalink
fix: add namespace support for the String.classify
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosgz committed Jan 21, 2025
1 parent 189096a commit bc69068
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/site_maps/primitives/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,24 @@ def classify
elsif defined?(ActiveSupport::Inflector)
ActiveSupport::Inflector.classify(self)
else
split("_").map(&:capitalize).join
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("::", "/")
Expand Down

0 comments on commit bc69068

Please sign in to comment.