aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext
diff options
context:
space:
mode:
authorYehuda Katz and Carl Lerche <wycats@gmail.com>2009-04-07 14:57:18 -0700
committerYehuda Katz and Carl Lerche <wycats@gmail.com>2009-04-07 14:57:18 -0700
commitc1aa5b0e14cd4bd27a5d8bd85cf7c36fa5911830 (patch)
treec4d08a6227e5a39cb65726fa40c2c54516068d24 /activesupport/lib/active_support/core_ext
parent9c8eaf8e254cf8ccaa6ecae3fdf1f468fbb60db8 (diff)
downloadrails-c1aa5b0e14cd4bd27a5d8bd85cf7c36fa5911830.tar.gz
rails-c1aa5b0e14cd4bd27a5d8bd85cf7c36fa5911830.tar.bz2
rails-c1aa5b0e14cd4bd27a5d8bd85cf7c36fa5911830.zip
Add depends_on, use, and setup to abstract up ideas about module inheritance.
Diffstat (limited to 'activesupport/lib/active_support/core_ext')
-rw-r--r--activesupport/lib/active_support/core_ext/module.rb1
-rw-r--r--activesupport/lib/active_support/core_ext/module/setup.rb26
2 files changed, 27 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/module.rb b/activesupport/lib/active_support/core_ext/module.rb
index da8d28ec13..cb31437094 100644
--- a/activesupport/lib/active_support/core_ext/module.rb
+++ b/activesupport/lib/active_support/core_ext/module.rb
@@ -8,6 +8,7 @@ require 'active_support/core_ext/module/loading'
require 'active_support/core_ext/module/aliasing'
require 'active_support/core_ext/module/model_naming'
require 'active_support/core_ext/module/synchronization'
+require 'active_support/core_ext/module/setup'
module ActiveSupport
module CoreExtensions
diff --git a/activesupport/lib/active_support/core_ext/module/setup.rb b/activesupport/lib/active_support/core_ext/module/setup.rb
new file mode 100644
index 0000000000..e6dfd0cf56
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/module/setup.rb
@@ -0,0 +1,26 @@
+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