git-agent for Rubygit-agent understands Rails MVC conventions, Active Record migrations, and Gemfile dependency changes, splitting your staged work into clean atomic commits with conventional messages.
diff --git a/app/services/invoice_generator.rb b/app/services/invoice_generator.rb
index 9a2c4f1..3b7d8e5 100644
--- a/app/services/invoice_generator.rb
+++ b/app/services/invoice_generator.rb
@@ -1,14 +1,26 @@
class InvoiceGenerator
def initialize(order)
@order = order
end
- def call
- Invoice.create!(
+ def call
+ raise ArgumentError, "order must be completed" unless @order.completed?
+
+ ActiveRecord::Base.transaction do
+ invoice = Invoice.create!(
number: generate_number,
order: @order,
- total: @order.total
- )
+ total: @order.total,
+ tax: calculate_tax(@order.total),
+ issued_at: Time.current
+ )
+ @order.update!(invoiced: true)
+ invoice
+ end
end
+ private
+
+ def calculate_tax(amount)
+ (amount * TaxRate.current).round(2)
+ end
endfeat(invoice): wrap generation in transaction and add tax calculation
- guard against invoicing incomplete orders with ArgumentError
- wrap Invoice.create! and order status update in a transaction for atomicity
- extract calculate_tax private method using current TaxRate record
- add issued_at and tax fields to the created invoice
Previously a failed order status update would leave an invoice without
marking the order as invoiced; the transaction ensures both records are
consistent or neither is written.brew install gitagenthq/tap/git-agent
# inside your Ruby project
git-agent init # detects Rails app structure and suggests scopesDoes git-agent handle Rails migration files separately from model changes?Can git-agent work with non-Rails Ruby projects?How does git-agent handle Ruby metaprogramming patterns?