Skip to content

Instantly share code, notes, and snippets.

@lastk
Forked from kurko/gist:2410930
Created April 18, 2012 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lastk/2413388 to your computer and use it in GitHub Desktop.
Save lastk/2413388 to your computer and use it in GitHub Desktop.
DCI in real code
class ReceivablesManagementContext
def initialize(params)
@params = params
end
def save_receivable
sanitize_controller_params
@receivable = AccountReceivable.new(@params[:account_receivable])
@receivable.customer_id = @params[:customer_id]
@receivable.save
end
private
def sanitize_controller_params
sanitize_date "due_to"
sanitize_currency "value"
end
def sanitize_date(key)
@receivable.due_to = DateSanitizer.parse_date_for_active_record @params[:account_receivable][key]
end
def sanitize_currency(key)
@receivable.value = CurrencyParser.to_float @params[:account_receivable][key]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment