Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

Commit

Permalink
Move common behavior to concern
Browse files Browse the repository at this point in the history
  • Loading branch information
msdundar committed Aug 1, 2018
1 parent a75d5ec commit 853bcf1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
8 changes: 4 additions & 4 deletions app/controllers/account/addresses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module Account
class AddressesController < ApplicationController
include LastUpdateFromMernis

before_action :set_address, only: %i[edit update destroy]
before_action :check_formality, only: %i[edit update destroy]
before_action :set_elapsed_time, only: %i[save_from_mernis]
Expand Down Expand Up @@ -46,10 +48,8 @@ def check_formality

def set_elapsed_time
formal_address = current_user.addresses.formal
return unless formal_address.present?

elapsed_time = (Time.zone.now - formal_address.first.updated_at) / 1.day
redirect_with('wait') if elapsed_time.present? && elapsed_time < 7
return if formal_address.blank?
elapsed_time(formal_address)
end

def redirect_with(message)
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/account/identities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module Account
class IdentitiesController < ApplicationController
include LastUpdateFromMernis

before_action :set_identity, only: %i[edit update destroy]
before_action :check_formality, only: %i[edit update destroy]
before_action :set_elapsed_time, only: %i[save_from_mernis]
Expand Down Expand Up @@ -46,10 +48,8 @@ def check_formality

def set_elapsed_time
formal_identity = current_user.identities.formal
return unless formal_identity.present?

elapsed_time = (Time.zone.now - formal_identity.first.updated_at) / 1.day
redirect_with('wait') if elapsed_time.present? && elapsed_time < 7
return if formal_identity.blank?
elapsed_time(formal_identity)
end

def redirect_with(message)
Expand Down
10 changes: 10 additions & 0 deletions app/controllers/concerns/last_update_from_mernis.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

module LastUpdateFromMernis
extend ActiveSupport::Concern

def elapsed_time(resource)
elapsed_time = (Time.zone.now - resource.first.updated_at) / 1.day
redirect_with('wait') if elapsed_time.present? && elapsed_time < 7
end
end

0 comments on commit 853bcf1

Please sign in to comment.