Skip to content

Instantly share code, notes, and snippets.

View DragosIorgulescu's full-sized avatar
🍪
must have cookies

Dragos Iorgulescu DragosIorgulescu

🍪
must have cookies
View GitHub Profile
@DragosIorgulescu
DragosIorgulescu / action.rb
Created November 24, 2022 17:35
An example of a basic custom action base object to use as a super class for service objects
class Action
attr_reader :data, :current_user, :request
def self.run(**args, &block)
context = args.delete(:context)
action = new(**args)
action.context = context unless context.blank?
action.run(&block)
@DragosIorgulescu
DragosIorgulescu / account_create.rb
Created November 24, 2022 17:22
1. You have a service object with the following method run inside a DB transaction:
def call
ActiveRecord::Base.transaction do
# use create! to ensure errors are raised if the create method fails
account = Account.create!(payload)
balance = Balance.create!(account: account)
# this may cause a corner case where if #send_new_account_notification raises an error,
# the account and balance records will be rolled back
# depending on the business logic requirements, this may be taken out of this block
send_new_account_notification(account)
@DragosIorgulescu
DragosIorgulescu / watchers.xml
Created August 8, 2018 12:50
WebStorm eslint file watchers
<TaskOptions>
<TaskOptions>
<option name="arguments" value="--config=$ProjectFileDir$/.eslintrc $FileDir$/$FileName$ --fix" />
<option name="checkSyntaxErrors" value="true" />
<option name="description" />
<option name="exitCodeBehavior" value="ERROR" />
<option name="fileExtension" value="jsx" />
<option name="immediateSync" value="false" />
<option name="name" value="ESLint Fix JSX" />
<option name="output" value="" />
@DragosIorgulescu
DragosIorgulescu / .pryrc
Last active August 29, 2015 14:06 — forked from justin808/.pryrc
## Useful Collections
def a_array
(1..6).to_a
end
def a_hash
{hello: "world", free: "of charge"}
end