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

Downcase value when comparing if the source is plural or singular. #52

Merged
merged 1 commit into from
Sep 22, 2020
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
7 changes: 2 additions & 5 deletions lib/xdrgen/generators/elixir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,15 @@ def name(named)
parent = name named.parent_defn if named.is_a?(AST::Concerns::NestedDefinition)

# NOTE: classify will strip plurality, so we restore it if necessary
plural = named.name.pluralize == named.name
plural = named.name.downcase.pluralize == named.name.downcase
base = named.name.underscore.classify
result = plural ? base.pluralize : base

"#{parent}#{result}"
end

def const_name(named)
# NOTE: classify will strip plurality, so we restore it if necessary
plural = named.name.pluralize == named.name
base = named.name.underscore.upcase
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we don't pluralize base, so this check is actually unnecessary.

plural ? base.pluralize : base
named.name.underscore.upcase
end

def member_name(member)
Expand Down
15 changes: 10 additions & 5 deletions lib/xdrgen/generators/javascript.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,23 @@ def name(named)
parent = name named.parent_defn if named.is_a?(AST::Concerns::NestedDefinition)

# NOTE: classify will strip plurality, so we restore it if necessary
plural = named.name.pluralize == named.name
#
# Downcase the value since pluralize adds a lower case `s`.
#
# Without downcasing, the following appears as singular, but it's plural:
#
# "BEGIN_SPONSORING_FUTURE_RESERVEs" == "BEGIN_SPONSORING_FUTURE_RESERVES"
# => false
#
plural = named.name.downcase.pluralize == named.name.downcase
base = named.name.underscore.classify
result = plural ? base.pluralize : base

"#{parent}#{result}"
end

def const_name(named)
# NOTE: classify will strip plurality, so we restore it if necessary
plural = named.name.pluralize == named.name
base = named.name.underscore.upcase
plural ? base.pluralize : base
named.name.underscore.upcase
end

def member_name(member)
Expand Down