From 2854535b02bcee3668bda02c76c3105fc24730d3 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 7 May 2009 10:29:22 -0500 Subject: Make module dependency DSL opt in --- .../lib/active_support/core_ext/module.rb | 1 - .../lib/active_support/core_ext/module/setup.rb | 26 ---------------------- .../lib/active_support/dependency_module.rb | 24 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 27 deletions(-) delete mode 100644 activesupport/lib/active_support/core_ext/module/setup.rb create mode 100644 activesupport/lib/active_support/dependency_module.rb (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/core_ext/module.rb b/activesupport/lib/active_support/core_ext/module.rb index fee91534e7..215c47b114 100644 --- a/activesupport/lib/active_support/core_ext/module.rb +++ b/activesupport/lib/active_support/core_ext/module.rb @@ -9,4 +9,3 @@ require 'active_support/core_ext/module/delegation' require 'active_support/core_ext/module/loading' require 'active_support/core_ext/module/model_naming' require 'active_support/core_ext/module/synchronization' -require 'active_support/core_ext/module/setup' diff --git a/activesupport/lib/active_support/core_ext/module/setup.rb b/activesupport/lib/active_support/core_ext/module/setup.rb deleted file mode 100644 index e6dfd0cf56..0000000000 --- a/activesupport/lib/active_support/core_ext/module/setup.rb +++ /dev/null @@ -1,26 +0,0 @@ -class Module - attr_accessor :_setup_block - attr_accessor :_dependencies - - def setup(&blk) - @_setup_block = blk - end - - def use(mod) - return if self < mod - - (mod._dependencies || []).each do |dep| - use dep - end - # raise "Circular dependencies" if self < mod - include mod - extend mod.const_get("ClassMethods") if mod.const_defined?("ClassMethods") - class_eval(&mod._setup_block) if mod._setup_block - end - - def depends_on(mod) - return if self < mod - @_dependencies ||= [] - @_dependencies << mod - end -end \ No newline at end of file diff --git a/activesupport/lib/active_support/dependency_module.rb b/activesupport/lib/active_support/dependency_module.rb new file mode 100644 index 0000000000..0e1cc67b53 --- /dev/null +++ b/activesupport/lib/active_support/dependency_module.rb @@ -0,0 +1,24 @@ +module ActiveSupport + module DependencyModule + def setup(&blk) + @_setup_block = blk + end + + def append_features(base) + return if base < self + (@_dependencies ||= []).each { |dep| base.send(:include, dep) } + super + end + + def included(base) + base.extend const_get("ClassMethods") if const_defined?("ClassMethods") + base.class_eval(&@_setup_block) if instance_variable_defined?("@_setup_block") + end + + def depends_on(mod) + return if self < mod + @_dependencies ||= [] + @_dependencies << mod + end + end +end -- cgit v1.2.3