Skip to content

Commit

Permalink
Adds default display name for state
Browse files Browse the repository at this point in the history
  • Loading branch information
the-spectator committed Oct 13, 2020
1 parent 81a0269 commit e0604ad
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/aasm/core/state.rb
Expand Up @@ -8,6 +8,7 @@ def initialize(name, klass, state_machine, options={})
@name = name
@klass = klass
@state_machine = state_machine
@default_display_name = name.to_s.gsub(/_/, ' ').capitalize
update(options)
end

Expand Down Expand Up @@ -55,12 +56,10 @@ def fire_callbacks(action, record, *args)

def display_name
@display_name = begin
if @fixed_display_name
@fixed_display_name
elsif Module.const_defined?(:I18n)
if Module.const_defined?(:I18n)
localized_name
else
name.to_s.gsub(/_/, ' ').capitalize
@default_display_name
end
end
end
Expand All @@ -78,7 +77,7 @@ def for_select

def update(options = {})
if options.key?(:display)
@fixed_display_name = options.delete(:display)
@default_display_name = options.delete(:display)
end
@options = options
self
Expand Down

0 comments on commit e0604ad

Please sign in to comment.