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

Use delete_suffix instead of gsub #796

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def run

unless @options["skip-migration-generation"]
attributes_without_options = attributes.map { |attribute| attribute.gsub(/{.*}$/, "") }
attributes_without_id = attributes_without_options.map { |attribute| attribute.gsub(/_id$/, "") }
attributes_without_id = attributes_without_options.map { |attribute| attribute.delete_suffix("_id") }
attributes_with_references = attributes_without_id.map { |attribute| attribute + ":references" }

generation_command = "bin/rails generate model #{child} #{attributes_with_references.join(" ")}"
Expand Down
4 changes: 2 additions & 2 deletions bullet_train-super_scaffolding/lib/scaffolding/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ def is_ids?
end

def name_without_id
name.gsub(/_id$/, "")
name.delete_suffix("_id")
end

def name_without_ids
name.gsub(/_ids$/, "").pluralize
name.delete_suffix("_ids").pluralize
end

def name_without_id_suffix
Expand Down
4 changes: 2 additions & 2 deletions bullet_train-super_scaffolding/lib/scaffolding/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ def check_required_options_for_attributes(scaffolding_type, attributes, child, p
attribute_options ||= {}
unless attribute_options[:vanilla]
name_without_id = if name.match?(/_id$/)
name.gsub(/_id$/, "")
name.delete_suffix("_id")
elsif name.match?(/_ids$/)
name.gsub(/_ids$/, "")
name.delete_suffix("_ids")
end

attribute_options[:class_name] ||= name_without_id.classify
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if other_options[:required]
options[:"aria-required"] = true
end

errors = [method, method.to_s.gsub(/_id$/, '').to_sym].uniq.map { |attribute| form.object.errors.full_messages_for(attribute) }.flatten
errors = [method, method.to_s.delete_suffix("_id").to_sym].uniq.map { |attribute| form.object.errors.full_messages_for(attribute) }.flatten
has_errors = errors.any? || partial.error? || other_options[:error].present?

options[:class] = "#{options[:class]} block w-full rounded-md shadow-sm font-light dark:bg-slate-800 dark:text-slate-300"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ options[:placeholder] ||= labels.placeholder if labels.placeholder
other_options ||= {}
other_options[:help] = [other_options[:help], labels.help].compact.join(" ")

errors = [method, method.to_s.gsub(/_id$/, '').to_sym].uniq.map { |attribute| form.object.errors.full_messages_for(attribute) }.flatten
errors = [method, method.to_s.delete_suffix("_id").to_sym].uniq.map { |attribute| form.object.errors.full_messages_for(attribute) }.flatten
has_errors = errors.any? || partial.error? || other_options[:error].present?

options[:class] = "#{options[:class]} block w-full rounded-md shadow-sm font-light"
Expand Down