1+ # frozen_string_literal: true
2+
13require 'active_model'
24require 'active_support/core_ext/hash/keys'
3- require 'active_support/core_ext/module/attribute_accessors.rb '
5+ require 'active_support/core_ext/module/attribute_accessors'
46require 'state_machines'
57require 'state_machines/integrations/base'
68require 'state_machines/integrations/active_model/version'
@@ -83,7 +85,7 @@ module Integrations #:nodoc:
8385 # state_machine do
8486 # ...
8587 # state :first_gear, :second_gear do
86- # validate {|vehicle| vehicle.speed_is_legal}
88+ # validate { |vehicle| vehicle.speed_is_legal }
8789 # end
8890 # end
8991 # end
@@ -292,7 +294,7 @@ module Integrations #:nodoc:
292294 # module StateMachine::Integrations::MyORM
293295 # include ActiveModel
294296 #
295- # mattr_accessor(:defaults) { action: :persist }
297+ # mattr_accessor(:defaults) { { action: :persist } }
296298 #
297299 # def self.matches?(klass)
298300 # defined?(::MyORM::Base) && klass <= ::MyORM::Base
@@ -324,10 +326,7 @@ def self.matching_ancestors
324326 def invalidate ( object , attribute , message , values = [ ] )
325327 if supports_validations?
326328 attribute = self . attribute ( attribute )
327- options = values . reduce ( { } ) do |h , ( key , value ) |
328- h [ key ] = value
329- h
330- end
329+ options = values . to_h { |key , value | [ key , value ] }
331330
332331 default_options = default_error_message_options ( object , attribute , message )
333332 object . errors . add ( attribute , message , **options , **default_options )
@@ -337,7 +336,7 @@ def invalidate(object, attribute, message, values = [])
337336 # Describes the current validation errors on the given object. If none
338337 # are specific, then the default error is interpeted as a "halt".
339338 def errors_for ( object )
340- object . errors . empty? ? 'Transition halted' : object . errors . full_messages * ', '
339+ object . errors . empty? ? 'Transition halted' : object . errors . full_messages . join ( ', ' )
341340 end
342341
343342 # Resets any errors previously added when invalidating the given object
0 commit comments