-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #201 from opedrosouza/remove-components
Back to defaults
- Loading branch information
Showing
115 changed files
with
582 additions
and
1,489 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# DATABASE CONFIG | ||
DB_NAME=boilerplate_development | ||
DB_PASS=password | ||
DB_USER=pedrosouza | ||
DB_HOST=localhost | ||
DB_PORT=5432 | ||
DB_URL=postgres://pedrosouza:password@localhost:5432/bolierplate_development |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# DATABASE CONFIG | ||
DB_NAME=boilerplate_test | ||
DB_PASS=password | ||
DB_USER=pedrosouza | ||
DB_HOST=localhost | ||
DB_PORT=5432 | ||
DB_URL=postgres://pedrosouza:password@localhost:5432/bolierplate_test |
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
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# frozen_string_literal: true | ||
module Currentable | ||
|
||
extend ActiveSupport::Concern | ||
|
||
included do |base| | ||
if base < ActionController::Base | ||
before_action :set_request_details | ||
end | ||
|
||
helper_method :current_account, :current_account_user, :other_accounts, :account_owner? | ||
end | ||
|
||
def current_account | ||
@current_account ||= Current.account | ||
end | ||
|
||
def current_account_user | ||
return unless current_account | ||
|
||
@current_account_user ||= current_account.account_users.includes(:user).find_by(user: current_user) | ||
end | ||
|
||
def other_accounts | ||
@other_accounts ||= current_user.accounts.order(name: :asc).where.not(id: current_account.id) | ||
end | ||
|
||
def account_owner? | ||
@account_owner ||= current_account_user&.owner? | ||
end | ||
|
||
private | ||
|
||
def set_request_details | ||
Current.request_id = request.uuid | ||
Current.user_agent = request.user_agent | ||
Current.ip_address = request.ip | ||
Current.user ||= current_user | ||
Current.account ||= account_from_session || account_from_cookies || fallback_account | ||
end | ||
|
||
def account_from_session | ||
return unless user_signed_in? && (account_id = session[:account_id]) | ||
|
||
current_user.accounts.includes(:users).find_by(id: account_id) | ||
end | ||
|
||
def account_from_cookies | ||
return unless user_signed_in? && (account_id = cookies.signed[:account_id]) | ||
|
||
current_user.accounts.includes(:users).find_by(id: account_id) | ||
end | ||
|
||
def fallback_account | ||
return unless user_signed_in? | ||
|
||
current_user.owned_accounts.includes(:users).first | ||
end | ||
|
||
end |
Oops, something went wrong.