Skip to content

Commit

Permalink
refactor to decrease complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
caiohsramos authored and Anil Kumar Maurya committed Mar 25, 2021
1 parent ca5bbfc commit adfeeb5
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/aasm/persistence/base.rb
Expand Up @@ -60,12 +60,7 @@ class Base
def state_with_scope(*args)
names = state_without_scope(*args)
names.each do |name|
if namespace?
# Create default scopes even when namespace? for backward compatibility
namepaced_name = "#{namespace}_#{name}"
create_scope(namepaced_name) if create_scope?(namepaced_name)
end
create_scope(name) if create_scope?(name)
create_scopes(name)
end
end
alias_method :state_without_scope, :state
Expand All @@ -78,7 +73,16 @@ def create_scope?(name)
end

def create_scope(name)
@klass.aasm_create_scope(@name, name)
@klass.aasm_create_scope(@name, name) if create_scope?(name)
end

def create_scopes(name)
if namespace?
# Create default scopes even when namespace? for backward compatibility
namepaced_name = "#{namespace}_#{name}"
create_scope(namepaced_name)
end
create_scope(name)
end
end # Base

Expand Down

0 comments on commit adfeeb5

Please sign in to comment.