Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zzaakiirr committed Oct 22, 2024
1 parent 97cd911 commit 926f933
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 121 deletions.
2 changes: 1 addition & 1 deletion lib/core/terraform_config/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module TerraformConfig
class Generator
SUPPORTED_TEMPLATE_KINDS = %w[gvc secret identity policy volumeset].freeze

InvalidTemplateError = Class.new(ArgumentError)
class InvalidTemplateError < ArgumentError; end

attr_reader :config, :template

Expand Down
12 changes: 3 additions & 9 deletions lib/patches/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,12 @@ def underscore
gsub("::", "/").gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').gsub(/([a-z\d])([A-Z])/, '\1_\2').tr("-", "_").downcase
end

# Covers only simple cases and used for pluralizing controlplane template kinds (`gvc`, `secret`, `policy`, etc.)
def pluralize
return self if empty?
return "#{self[...-1]}ies" if end_with?("y")

if end_with?("ies")
self
elsif end_with?("s", "x", "z", "ch", "sh")
end_with?("es") ? self : "#{self}es"
elsif end_with?("y")
"#{self[...-1]}ies"
else
end_with?("s") ? self : "#{self}s"
end
"#{self}s"
end
end
# rubocop:enable Style/OptionalBooleanParameter, Lint/UnderscorePrefixedVariableName
44 changes: 6 additions & 38 deletions spec/patches/string_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,17 @@
end
end

context "when word already ends with 'ies'" do
it "returns the word unchanged" do
expect("cities".pluralize).to eq("cities")
expect("babies".pluralize).to eq("babies")
end
end

context "when word ends with 's', 'x', 'z', 'ch', or 'sh'" do
it "adds 'es' to the end if it doesn't already end with 'es'" do
expect("bus".pluralize).to eq("buses")
expect("box".pluralize).to eq("boxes")
expect("buzz".pluralize).to eq("buzzes")
expect("church".pluralize).to eq("churches")
expect("dish".pluralize).to eq("dishes")
end

it "returns the word unchanged if it already ends with 'es'" do
expect("buses".pluralize).to eq("buses")
expect("boxes".pluralize).to eq("boxes")
end
end

context "when word ends with 'y'" do
it "changes 'y' to 'ies'" do
expect("city".pluralize).to eq("cities")
expect("baby".pluralize).to eq("babies")
end
end

context "when word doesn't end with 'y', 's', 'x', 'z', 'ch', or 'sh'" do
it "adds 's' to the end if it doesn't already end with 's'" do
expect("cat".pluralize).to eq("cats")
expect("dog".pluralize).to eq("dogs")
expect("book".pluralize).to eq("books")
expect("policy".pluralize).to eq("policies")
expect("identity".pluralize).to eq("identities")
end
end

context "when word is a single character" do
it "applies the rules correctly" do
expect("a".pluralize).to eq("as")
expect("s".pluralize).to eq("ses")
expect("x".pluralize).to eq("xes")
expect("y".pluralize).to eq("ies")
context "when word does not end with 'y'" do
it "adds 's' to the end of the word" do
expect("secret".pluralize).to eq("secrets")
expect("volumeset".pluralize).to eq("volumesets")
end
end
end
Expand Down
73 changes: 0 additions & 73 deletions spec/pathces/hash_spec.rb

This file was deleted.

0 comments on commit 926f933

Please sign in to comment.