This file contains 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
ActiveRecord::Base.establish_connection( adapter: 'sqlite3', database: ":memory:" ) | |
ActiveRecord::Schema.define(version: 1) { create_table(:users) { |t| t.string :name; t.string :email } } | |
class User < ActiveRecord::Base; end | |
User.create(name: 'Vitaly', email: '[email protected]') |
This file contains 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
def call(fields) | |
fields = yield validate_fields(fields) | |
email = yield validate_email(fields['email']) | |
user = yield find_user(fields['id']) | |
user = yield update_user(user, {name: fields['name'], email: fields['email']}) | |
sent = yield send_email(user, :profile_updated) | |
Success(user) | |
end |
This file contains 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
def find_user(id) | |
Try { user_model.find_by(id: id) } | |
end | |
def update_user(user, data) | |
Try do | |
user.update(data) | |
user.reload | |
end | |
end |
This file contains 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
patch '/users/:id/' do | |
result = UserUpdater.new(User, config.mailer).call(params).to_result | |
# a simple, "unambitious" version | |
if result.success? | |
result.sucess.to_json | |
else | |
{error: result.failure}.to_json | |
end | |
end |
This file contains 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
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc. | |
# Initialization code that may require console input (password prompts, [y/n] | |
# confirmations, etc.) must go above this block; everything else may go below. | |
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then | |
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" | |
fi | |
source "${HOME}/.zgen/zgen.zsh" | |
#if the init script doesn't exist |
OlderNewer