diff options
author | rick <technoweenie@gmail.com> | 2008-06-27 23:29:47 -0700 |
---|---|---|
committer | rick <technoweenie@gmail.com> | 2008-06-27 23:29:47 -0700 |
commit | b7c6ceff9a31cc478c4bc89d57980900a775fbed (patch) | |
tree | a37c0f18910e7c2d822e9158d9951cec48a5e8d4 /activemodel | |
parent | aec3c7aa72c89e37edae4d14ac98d7a6de4a195c (diff) | |
download | rails-b7c6ceff9a31cc478c4bc89d57980900a775fbed.tar.gz rails-b7c6ceff9a31cc478c4bc89d57980900a775fbed.tar.bz2 rails-b7c6ceff9a31cc478c4bc89d57980900a775fbed.zip |
tweak activemodel load order a bit
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/Rakefile | 16 | ||||
-rw-r--r-- | activemodel/lib/active_model.rb | 20 | ||||
-rw-r--r-- | activemodel/lib/active_model/base.rb | 4 | ||||
-rw-r--r-- | activemodel/lib/active_model/callbacks.rb | 2 | ||||
-rw-r--r-- | activemodel/lib/active_model/core.rb | 7 | ||||
-rw-r--r-- | activemodel/lib/active_model/observing.rb | 18 | ||||
-rw-r--r-- | activemodel/lib/active_model/validations.rb | 2 |
7 files changed, 39 insertions, 30 deletions
diff --git a/activemodel/Rakefile b/activemodel/Rakefile index 87e9b547f3..034c2fbd01 100644 --- a/activemodel/Rakefile +++ b/activemodel/Rakefile @@ -1,11 +1,19 @@ #!/usr/bin/env ruby -$LOAD_PATH << File.join(File.dirname(__FILE__), 'vendor', 'rspec', 'lib') require 'rake' -require 'spec/rake/spectask' +require 'rake/testtask' require 'rake/rdoctask' +task :default => :test + +Rake::TestTask.new do |t| + t.libs << "test" + t.pattern = 'test/**/*_test.rb' + t.verbose = true + t.warning = true +end + # Generate the RDoc documentation -Rake::RDocTask.new { |rdoc| +Rake::RDocTask.new do |rdoc| rdoc.rdoc_dir = 'doc' rdoc.title = "Active Model" rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object' @@ -13,4 +21,4 @@ Rake::RDocTask.new { |rdoc| rdoc.template = "#{ENV['template']}.rb" if ENV['template'] rdoc.rdoc_files.include('README', 'CHANGES') rdoc.rdoc_files.include('lib/**/*.rb') -}
\ No newline at end of file +end
\ No newline at end of file diff --git a/activemodel/lib/active_model.rb b/activemodel/lib/active_model.rb index 369c7fed33..4ed7b0889d 100644 --- a/activemodel/lib/active_model.rb +++ b/activemodel/lib/active_model.rb @@ -1,17 +1,5 @@ -$LOAD_PATH << File.join(File.dirname(__FILE__), '..', '..', 'activesupport', 'lib') - -# premature optimization? -require 'active_support/inflector' -require 'active_support/core_ext/string/inflections' -String.send :include, ActiveSupport::CoreExtensions::String::Inflections - -require 'active_model/base' require 'active_model/observing' -require 'active_model/callbacks' -require 'active_model/validations' - -ActiveModel::Base.class_eval do - include ActiveModel::Observing - include ActiveModel::Callbacks - include ActiveModel::Validations -end
\ No newline at end of file +# disabled until they're tested +# require 'active_model/callbacks' +# require 'active_model/validations' +require 'active_model/base'
\ No newline at end of file diff --git a/activemodel/lib/active_model/base.rb b/activemodel/lib/active_model/base.rb index 1141156da4..a500adfdf1 100644 --- a/activemodel/lib/active_model/base.rb +++ b/activemodel/lib/active_model/base.rb @@ -1,4 +1,8 @@ module ActiveModel class Base + include Observing + # disabled, until they're tested + # include Callbacks + # include Validations end end
\ No newline at end of file diff --git a/activemodel/lib/active_model/callbacks.rb b/activemodel/lib/active_model/callbacks.rb index 0114fc386b..1dd20156ec 100644 --- a/activemodel/lib/active_model/callbacks.rb +++ b/activemodel/lib/active_model/callbacks.rb @@ -1,3 +1,5 @@ +require 'active_model/observing' + module ActiveModel module Callbacks diff --git a/activemodel/lib/active_model/core.rb b/activemodel/lib/active_model/core.rb new file mode 100644 index 0000000000..47b968e121 --- /dev/null +++ b/activemodel/lib/active_model/core.rb @@ -0,0 +1,7 @@ +# This file is required by each major ActiveModel component for the core requirements. This allows you to +# load individual pieces of ActiveModel as needed. +$LOAD_PATH << File.join(File.dirname(__FILE__), '..', '..', '..', 'activesupport', 'lib') + +# premature optimization? +# So far, we only need the string inflections and not the rest of ActiveSupport. +require 'active_support/inflector'
\ No newline at end of file diff --git a/activemodel/lib/active_model/observing.rb b/activemodel/lib/active_model/observing.rb index db758f5185..9e99d7472c 100644 --- a/activemodel/lib/active_model/observing.rb +++ b/activemodel/lib/active_model/observing.rb @@ -1,4 +1,6 @@ require 'observer' +require 'singleton' +require 'active_model/core' module ActiveModel module Observing @@ -73,7 +75,7 @@ module ActiveModel # Start observing the declared classes and their subclasses. def initialize self.observed_classes = self.class.models if self.class.models - observed_classes.each { |klass| add_observer! klass } + observed_classes.each { |klass| klass.add_observer(self) } end # Send observed_method(object) if the method exists. @@ -85,16 +87,12 @@ module ActiveModel # Passes the new subclass. def observed_class_inherited(subclass) #:nodoc: self.class.observe(observed_classes + [subclass]) - add_observer!(subclass) + subclass.add_observer(self) end - protected - def observed_classes - @observed_classes ||= [self.class.observed_class] - end - - def add_observer!(klass) - klass.add_observer(self) - end + protected + def observed_classes + @observed_classes ||= [self.class.observed_class] + end end end
\ No newline at end of file diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb index 34ef3b8f6e..6b692e6a9a 100644 --- a/activemodel/lib/active_model/validations.rb +++ b/activemodel/lib/active_model/validations.rb @@ -1,3 +1,5 @@ +require 'active_model/observing' + module ActiveModel module Validations def self.included(base) # :nodoc: |