Skip to content

Commit

Permalink
Minor syntax / doc tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
obrie committed Jul 27, 2010
1 parent 10a1784 commit 4718436
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/state_machine/integrations/active_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ module ClassMethods
def extended(base) #:nodoc:
require 'state_machine/integrations/active_model/observer'

if Object.const_defined?(:I18n)
if defined?(I18n)
locale = "#{File.dirname(__FILE__)}/active_model/locale.rb"
I18n.load_path.unshift(locale) unless I18n.load_path.include?(locale)
end
Expand Down
16 changes: 8 additions & 8 deletions lib/state_machine/integrations/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -331,17 +331,17 @@ def self.extended(base) #:nodoc:

::ActiveRecord::Observer.class_eval do
include StateMachine::Integrations::ActiveModel::Observer
end unless ::ActiveRecord::Observer.included_modules.include?(StateMachine::Integrations::ActiveModel::Observer)
end unless ::ActiveRecord::Observer < StateMachine::Integrations::ActiveModel::Observer

if Object.const_defined?(:I18n)
if defined?(I18n)
locale = "#{File.dirname(__FILE__)}/active_record/locale.rb"
I18n.load_path.unshift(locale) unless I18n.load_path.include?(locale)
end
end

# Adds a validation error to the given object
def invalidate(object, attribute, message, values = [])
if Object.const_defined?(:I18n)
if defined?(I18n)
super
else
object.errors.add(self.attribute(attribute), generate_message(message, values))
Expand All @@ -366,7 +366,7 @@ def runs_validations_on_action?

# Only adds dirty tracking support if ActiveRecord supports it
def supports_dirty_tracking?(object)
defined?(::ActiveRecord::Dirty) && object.respond_to?("#{self.attribute}_changed?") || super
defined?(::ActiveRecord::Dirty) && object.respond_to?("#{attribute}_changed?") || super
end

# Always uses the <tt>:activerecord</tt> translation scope
Expand All @@ -386,17 +386,17 @@ def default_error_message_options(object, attribute, message)

# Only allows translation of I18n is available
def translate(klass, key, value)
if Object.const_defined?(:I18n)
if defined?(I18n)
super
else
value ? value.to_s.humanize.downcase : 'nil'
end
end

# Attempts to look up a class's ancestors via:
# * #lookup_ancestors
# * #self_and_descendants_from_active_record
# * #self_and_descendents_from_active_record
# * #lookup_ancestors (3.0.0+)
# * #self_and_descendants_from_active_record (2.3.2 - 2.3.x)
# * #self_and_descendents_from_active_record (2.0.0 - 2.3.1)
def ancestors_for(klass)
if ::ActiveRecord::VERSION::MAJOR >= 3
super
Expand Down
2 changes: 1 addition & 1 deletion lib/state_machine/machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ def owner_class=(klass)
end

# Add class-/instance-level methods to the owner class for state initialization
unless owner_class.included_modules.include?(StateMachine::InstanceMethods)
unless owner_class < StateMachine::InstanceMethods
owner_class.class_eval do
extend StateMachine::ClassMethods
include StateMachine::InstanceMethods
Expand Down

0 comments on commit 4718436

Please sign in to comment.