Skip to content

Commit 93f30ca

Browse files
committed
feat: camelize without inflection
1 parent 3cc6877 commit 93f30ca

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/anchor/types.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,21 @@ def default_name
5555
end
5656
end
5757

58+
def self.camelize_without_inflection(val)
59+
vals = val.split("_")
60+
if vals.length == 1
61+
vals[0]
62+
else
63+
([vals[0]] + vals[1..].map(&:capitalize)).join("")
64+
end
65+
end
66+
5867
# @param value [String, Symbol]
5968
# @return [String]
6069
def self.convert_case(value)
6170
case Anchor.config.field_case
6271
when :camel then value.to_s.underscore.camelize(:lower)
72+
when :camel_without_inflection then camelize_without_inflection(value.to_s.underscore)
6373
when :kebab then value.to_s.underscore.dasherize
6474
when :snake then value.to_s.underscore
6575
else value

spec/example/config/initializers/anchor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Anchor
22
configure do |c|
3-
c.field_case = :camel
3+
c.field_case = :camel_without_inflection
44
c.use_active_record_comment = true
55
c.use_active_record_presence = true
66
c.infer_nullable_relationships_as_optional = true

0 commit comments

Comments
 (0)