-
-
Save lastk/2413388 to your computer and use it in GitHub Desktop.
DCI in real code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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