Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/amber_cli/commands/database.cr
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ module AmberCLI::Commands
when "create"
create_database
when "seed"
Amber::CLI::Helpers.run("crystal db/seeds.cr", wait: true, shell: true)
Amber::CLI::Helpers.run("crystal db/seeds.cr", wait: true)
info "Seeded database"
when "migrate"
migrate
Expand Down
8 changes: 5 additions & 3 deletions src/amber_cli/helpers/helpers.cr
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ module Amber::CLI::Helpers
File.write(app_file_path, application.gsub(injection_marker, replacement)) if deps.size > 0
end

def self.run(command, wait = true, shell = true)
def self.run(command : String, wait = true)
parsed_args = Process.parse_arguments(command)
cmd = parsed_args.shift? || ""
if wait
Process.run(command, shell: shell, output: Process::Redirect::Inherit, error: Process::Redirect::Inherit)
Process.run(cmd, args: parsed_args, shell: false, output: Process::Redirect::Inherit, error: Process::Redirect::Inherit)
else
Process.new(command, shell: shell, output: Process::Redirect::Inherit, error: Process::Redirect::Inherit)
Process.new(cmd, args: parsed_args, shell: false, output: Process::Redirect::Inherit, error: Process::Redirect::Inherit)
end
rescue ex : IO::Error
# typically means we could not find the executable
Expand Down
4 changes: 2 additions & 2 deletions src/amber_cli/helpers/process_runner.cr
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ module Sentry
end

private def start_process(run_command_run)
process = Amber::CLI::Helpers.run(run_command_run, wait: false, shell: false)
process = Amber::CLI::Helpers.run(run_command_run, wait: false)
if process.is_a? Process
@processes["run"] ||= Array(Process).new
@processes["run"] << process
Expand Down Expand Up @@ -178,7 +178,7 @@ module Sentry
end

log task, "Starting..."
process = Amber::CLI::Helpers.run(run_command, wait: false, shell: true)
process = Amber::CLI::Helpers.run(run_command, wait: false)
if process.is_a? Process
@processes[task] ||= Array(Process).new
@processes[task] << process
Expand Down
9 changes: 9 additions & 0 deletions src/amber_cli/vendor/inflector/ai_transformer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ module AmberCLI::Vendor::Inflector::AITransformer
end
end

# Cache limit to prevent memory leaks in persistent instances
MAX_CACHE_SIZE = 1000

# Cache for AI transformation results
@@cache = {} of String => String
@@config = Config.new
Expand All @@ -41,11 +44,17 @@ module AmberCLI::Vendor::Inflector::AITransformer
# Check cache first
cache_key = "#{word}:#{transformation}"
if cached_result = @@cache[cache_key]?
# Move to end (most recently used)
@@cache.delete(cache_key)
@@cache[cache_key] = cached_result
return cached_result
end

# Try AI transformation
if result = call_ai_service(word, transformation)
if @@cache.size >= MAX_CACHE_SIZE
@@cache.delete(@@cache.first_key)
end
@@cache[cache_key] = result
return result
end
Expand Down
6 changes: 6 additions & 0 deletions src/amber_cli/vendor/inflector/inflector.cr
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module AmberCLI::Vendor::Inflector
# pluralize("sheep") # => "sheep"
# pluralize("foot") # => "feet" # Fixed!
# pluralize("child") # => "children"
@[TargetFeature("+avx2")]
def pluralize(word : String) : String
# Try local rules first
local_result = apply_inflections(word, @@plurals)
Expand All @@ -47,6 +48,7 @@ module AmberCLI::Vendor::Inflector
# singularize('sheep') # => "sheep"
# singularize('feet') # => "foot" # Fixed!
# singularize('children') # => "child"
@[TargetFeature("+avx2")]
def singularize(word : String) : String
# Try local rules first
local_result = apply_inflections(word, @@singulars)
Expand All @@ -66,6 +68,7 @@ module AmberCLI::Vendor::Inflector
#
# classify("egg_and_hams") # => "EggAndHam"
# classify("posts") # => "Post"
@[TargetFeature("+avx2")]
def classify(table_name : String) : String
# Use Crystal's built-in camelcase method instead of custom implementation
singularize(table_name.sub(/.*\./, "")).camelcase
Expand All @@ -79,6 +82,7 @@ module AmberCLI::Vendor::Inflector
#
# foreign_key("Message") # => "message_id"
# foreign_key("Admin::Post") # => "post_id"
@[TargetFeature("+avx2")]
def foreign_key(class_name : String, separate_class_name_and_id_with_underscore = true) : String
# Use Crystal's built-in underscore method and simple demodulize
demodulized = demodulize(class_name)
Expand All @@ -93,6 +97,7 @@ module AmberCLI::Vendor::Inflector
#
# demodulize("ActiveRecord::CoreExtensions::String::Inflections") # => "Inflections"
# demodulize("Inflections") # => "Inflections"
@[TargetFeature("+avx2")]
private def demodulize(path : String) : String
if i = path.rindex("::")
path[(i + 2)..-1]
Expand All @@ -102,6 +107,7 @@ module AmberCLI::Vendor::Inflector
end

# Apply inflection rules for pluralize and singularize
@[TargetFeature("+avx2")]
private def apply_inflections(word : String, rules : Array({Regex, String})) : String
result = word.to_s

Expand Down