class ActiveRecord::Events::Macro
Public Class Methods
new(event_name, options)
click to toggle source
# File lib/active_record/events/macro.rb, line 4 def initialize(event_name, options) @event_name = event_name.to_s @options = options end
Public Instance Methods
to_s()
click to toggle source
# File lib/active_record/events/macro.rb, line 9 def to_s "has_event :#{event_name}#{options_list}" end
Private Instance Methods
convert_value(value)
click to toggle source
# File lib/active_record/events/macro.rb, line 27 def convert_value(value) symbol_or_string?(value) ? ":#{value}" : value end
event_name()
click to toggle source
# File lib/active_record/events/macro.rb, line 15 def event_name @event_name.underscore end
options()
click to toggle source
# File lib/active_record/events/macro.rb, line 23 def options @options.map { |k, v| "#{k}: #{convert_value(v)}" } end
options_list()
click to toggle source
# File lib/active_record/events/macro.rb, line 19 def options_list options.unshift('').join(', ') if options.present? end
symbol_or_string?(value)
click to toggle source
# File lib/active_record/events/macro.rb, line 31 def symbol_or_string?(value) value.is_a?(Symbol) || value.is_a?(String) end