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/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/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
# 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
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
# services/mail_service/main.rb | |
require 'barrister-redis' | |
opts = { | |
database_url: ENV['OPENREDIS_URL'], | |
list_name: 'mail_service' | |
} | |
Barrister::RedisContainer.new('./interface.json', MailService.new, opts).start |
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/main.rb | |
require 'activerecord' | |
require 'barrister-redis' | |
# establish a connection to the database | |
db_config = YAML.load(ERB.new(File.read('../../config/database.yml')).result) | |
ActiveRecord::Base.establish_connection db_config[ENV['RACK_ENV'] || 'development'] | |
# create our MailService proxy |
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' | |
require 'barrister-redis' | |
class Services | |
# ... | |
def self.proxy_services |
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
# Procfile | |
web: bundle exec rails s -p $PORT | |
mail_service: sh -c 'cd services/mail_service; ./main.rb' | |
user_service: sh -c 'cd services/user_service; ./main.rb' |
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/main.rb | |
require 'barrister-sinatra' | |
opts = { | |
mount_path: '/api', | |
port: ENV['PORT'] | |
} | |
Barrister::SinatraContainer.new('./interface.json', MailService.new, opts).start |