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 UsersController < ApplicationController | |
# ... | |
def create | |
Services.user_service.create_user user_params | |
redirect_to action: 'index' | |
end | |
# ... |
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
# config/initializers/services.rb | |
require 'barrister-rails' | |
class Services | |
def self.user_service | |
@@services ||= proxy_services | |
@@services[:user_service] | |
end |
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
# services/user_service/models/user.rb | |
class UserService | |
class User < ActiveRecord::Base | |
validates :email, uniqueness: true | |
end | |
end |
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
# services/user_service/implementation.rb | |
class UserService | |
USER_ATTRIBUTES = %w(id full_name email phone_number) | |
def initialize(mail_service) | |
@mail_service = mail_service | |
end | |
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
# services/mail_service/implementation.rb | |
class MailService | |
def send_email(from, to, subject, body) | |
opts = { from: from, to: to, subject: subject, body: body } | |
mail = ActionMailer::Base.mail opts | |
!!mail.deliver # return true if we're g2g | |
end |
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
// services/user_service/interface.idl | |
struct UserProperties { | |
email string | |
full_name string | |
phone_number string [optional] | |
} | |
struct User extends UserProperties { | |
id int |
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
// services/mail_service/interface.idl | |
interface MailService { | |
send_email(from string, to string, subject string, body string) bool | |
} |
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 UsersController < ApplicationController | |
def index | |
@users = User.all | |
end | |
def new; end | |
def create | |
User.new(user_params).save! |
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 User < ActiveRecord::Base | |
after_create :notify_added | |
validates :email, uniqueness: true | |
def notify_added | |
UserMailer.email(self).deliver | |
end | |
end |
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 User < ActiveRecord::Base | |
after_create :notify_added | |
validates :email, uniqueness: true | |
def notify_added | |
UserMailer.email(self).deliver | |
end | |
end |