Skip to content

Commit

Permalink
Fixed regression introduced in PR rails#39.
Browse files Browse the repository at this point in the history
- Also added test so it won't happen again.
- Added bundler config to fix insecure git protocol warnings.
- Removed a couple of unneeded deps.

Resolves rails#45
Resolves rails#49
  • Loading branch information
mvastola committed Feb 4, 2017
1 parent 54110b5 commit 9f76278
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .bundle/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
BUNDLE_GITHUB__HTTPS: "true"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.gem
*.rbc
.bundle
.bundle/*
!.bundle/config
.config
.yardoc
Gemfile.lock
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in active_record-observers.gemspec
gemspec
gem 'rails', github: 'rails/rails', branch: '5-0-stable'
gem 'activeresource', github: 'rails/activeresource'
gem 'activeresource', github: 'rails/activeresource', branch: 'master'

gem 'mocha', require: false
22 changes: 18 additions & 4 deletions lib/rails/observers/active_model/observing.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
require 'set'
require 'singleton'
require 'rails/observers/active_model/observer_array'
require 'active_support/core_ext/module/aliasing'
require 'active_support/core_ext/module/remove_method'
require 'active_support/core_ext/string/inflections'
require 'active_support/core_ext/enumerable'
require 'active_support/core_ext/object/try'
require 'active_support/descendants_tracker'

Expand All @@ -13,7 +12,11 @@ module Observing
extend ActiveSupport::Concern

included do
extend ActiveSupport::DescendantsTracker
extend ::ActiveSupport::DescendantsTracker
def self.inherited(subclass)
super
subclass.observer_orm.instantiate_observers
end
end

module ClassMethods
Expand Down Expand Up @@ -74,7 +77,7 @@ def observers
#
# Foo.observer_instances # => [#<FooObserver:0x007fc212c40820>]
def observer_instances
@observer_instances ||= []
@observer_instances ||= Set.new
end

# Instantiate the global observers.
Expand Down Expand Up @@ -176,6 +179,17 @@ def count_observers
observers_count
end

# Inheritable, read-only, lazily-determined, memoized class variable reader
# referring to the Active.*::Base class that included ::ActiveModel::Observing
def observer_orm #:nodoc:#
@@observer_orm ||= begin
self_and_parents = self.parents.unshift(self)
self_and_parents.detect do |klass|
klass.included_modules.include?(::ActiveModel::Observing)
end
end
end

protected
def instantiate_observer(observer) #:nodoc:
# string/symbol
Expand Down

0 comments on commit 9f76278

Please sign in to comment.