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
class Person | |
attr_accessor :first_name | |
attr_accessor :last_name | |
attr_accessor :dob | |
attr_reader :age | |
def initialize(first_name, last_name, dob) | |
self.first_name = first_name |
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
#!/bin/bash | |
CUR_PATH=$1 | |
if [ -z $CUR_PATH ] | |
then | |
CUR_PATH=`pwd` | |
fi | |
cd $CUR_PATH | |
git diff --name-only | xargs rubocop --format simple |
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
#!/bin/bash | |
while getopts ":h:u:w:d:p:" opt; do | |
case $opt in | |
h) DB_HOST="$OPTARG" | |
;; | |
u) DB_USER="$OPTARG" | |
;; | |
w) DB_PASSWORD="$OPTARG" | |
;; |
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
class UsersController < ApplicationController | |
def create | |
if @user.save | |
render json: @user, status: 200 | |
else | |
render json @user.errors, status: 400 | |
end | |
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
class User < ApplicationRecord | |
validates :first_name, presence: true | |
validates :last_name, presence: true | |
validates :email, presence: true | |
validates :token, presence: true | |
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
class User < ApplicationRecord | |
validates :first_name, presence: true | |
validates :last_name, presence: true | |
validates :email, presence: true | |
validates :token, presence: true | |
before_create :generate_token | |
after_create :send_welcome_email | |
private |
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
module UsersHelper | |
def generate_token(user) | |
uri = URI("https://example.com/#{user.email}") | |
response = Net::HTTP.get_response(uri) | |
if response.code == '200' | |
return JSON.parse(response.body)[:token] | |
end | |
end | |
def send_welcome_email(user) |
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
class UsersController < ApplicationController | |
include UsersHelper | |
def create | |
if params[:token].blank? | |
@user.token = generate_token(@user) | |
end | |
if @user.save | |
send_welcome_email(@user) if params[:send_email] | |
render json: @user, status: 200 |
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
class TokenProvider | |
def self.generate(email) | |
uri = URI("https://example.com/#{email}") | |
response = Net::HTTP.get_response(uri) | |
if response.code == '200' | |
return JSON.parse(response.body)[:token] | |
end | |
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
# service name hints that it does | |
class CreateUserService | |
# default attributes that all services should have | |
attr_reader :errors, :messages, :output | |
# custom attributes for what this service does | |
attr_reader :user, :send_email | |
# we receive all parameters in the initialization | |
def initialize(user:, send_email: true) |
OlderNewer