Skip to content

Commit

Permalink
Uses the default_display_name for localizer
Browse files Browse the repository at this point in the history
  • Loading branch information
the-spectator authored and Anil Kumar Maurya committed Oct 15, 2020
1 parent 92e6555 commit 8560d40
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/aasm/core/event.rb
Expand Up @@ -4,7 +4,7 @@ module AASM::Core
class Event
include AASM::DslHelper

attr_reader :name, :state_machine, :options
attr_reader :name, :state_machine, :options, :default_display_name

def initialize(name, state_machine, options = {}, &block)
@name = name
Expand All @@ -13,6 +13,7 @@ def initialize(name, state_machine, options = {}, &block)
@valid_transitions = {}
@guards = Array(options[:guard] || options[:guards] || options[:if])
@unless = Array(options[:unless]) #TODO: This could use a better name
@default_display_name = name.to_s.gsub(/_/, ' ').capitalize

# from aasm4
@options = options # QUESTION: .dup ?
Expand Down
2 changes: 1 addition & 1 deletion lib/aasm/core/state.rb
Expand Up @@ -2,7 +2,7 @@

module AASM::Core
class State
attr_reader :name, :state_machine, :options
attr_reader :name, :state_machine, :options, :default_display_name

def initialize(name, klass, state_machine, options={})
@name = name
Expand Down
12 changes: 10 additions & 2 deletions lib/aasm/localizer.rb
Expand Up @@ -5,7 +5,7 @@ def human_event_name(klass, event)
list << :"#{i18n_scope(klass)}.events.#{i18n_klass(ancestor)}.#{event}"
list
end
translate_queue(checklist) || I18n.translate(checklist.shift, :default => event.to_s.gsub(/_/, ' ').capitalize)
translate_queue(checklist) || I18n.translate(checklist.shift, :default => default_display_name(event))
end

def human_state_name(klass, state)
Expand All @@ -14,7 +14,7 @@ def human_state_name(klass, state)
list << item_for(klass, state, ancestor, :old_style => true)
list
end
translate_queue(checklist) || I18n.translate(checklist.shift, :default => state.to_s.gsub(/_/, ' ').capitalize)
translate_queue(checklist) || I18n.translate(checklist.shift, :default => default_display_name(state))
end

private
Expand Down Expand Up @@ -52,5 +52,13 @@ def ancestors_list(klass)
ancestor.respond_to?(:model_name) && not_active_record_base
end
end

def default_display_name(object) # Can use better arguement name
if object.respond_to?(:default_display_name)
object.default_display_name
else
object.to_s.gsub(/_/, ' ').capitalize
end
end
end
end # AASM

0 comments on commit 8560d40

Please sign in to comment.