From cc76754d11de5d5457171a7bb50904f70fa8ae9e Mon Sep 17 00:00:00 2001 From: rick Date: Thu, 25 Sep 2008 00:12:30 -0700 Subject: [PATCH] remove the last bits of self.included and self.extended extensions --- init.rb | 2 +- lib/permalink_fu.rb | 29 +++++++++++++---------------- test/permalink_fu_test.rb | 2 +- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/init.rb b/init.rb index 5dc92b7..bdedd1f 100644 --- a/init.rb +++ b/init.rb @@ -1 +1 @@ -ActiveRecord::Base.send :include, PermalinkFu \ No newline at end of file +ActiveRecord::Base.extend PermalinkFu::PluginMethods \ No newline at end of file diff --git a/lib/permalink_fu.rb b/lib/permalink_fu.rb index 0cfc35e..c0923de 100644 --- a/lib/permalink_fu.rb +++ b/lib/permalink_fu.rb @@ -21,10 +21,6 @@ def escape(string) result end end - - def self.included(base) - base.extend PluginMethods - end # This is the plugin method available on all ActiveRecord models. module PluginMethods @@ -57,32 +53,33 @@ def has_permalink(attr_names = [], permalink_field = nil, options = {}) options = permalink_field permalink_field = nil end - extend ClassMethods - self.permalink_attributes = Array(attr_names) - self.permalink_field = (permalink_field || 'permalink').to_s - self.permalink_options = {:unique => true}.update(options) - setup_permalink_fu + ClassMethods.setup_permalink_fu_on self do + self.permalink_attributes = Array(attr_names) + self.permalink_field = (permalink_field || 'permalink').to_s + self.permalink_options = {:unique => true}.update(options) + end end end # Contains class methods for ActiveRecord models that have permalinks module ClassMethods - def self.extended(base) + def self.setup_permalink_fu_on(base) + base.extend self class << base attr_accessor :permalink_options attr_accessor :permalink_attributes attr_accessor :permalink_field end base.send :include, InstanceMethods - end - def setup_permalink_fu - if permalink_options[:unique] - before_validation :create_unique_permalink + yield + + if base.permalink_options[:unique] + base.before_validation :create_unique_permalink else - before_validation :create_common_permalink + base.before_validation :create_common_permalink end - class << self + class << base alias_method :define_attribute_methods_without_permalinks, :define_attribute_methods alias_method :define_attribute_methods, :define_attribute_methods_with_permalinks end diff --git a/test/permalink_fu_test.rb b/test/permalink_fu_test.rb index de6a519..e64c0e4 100644 --- a/test/permalink_fu_test.rb +++ b/test/permalink_fu_test.rb @@ -22,7 +22,7 @@ def self.inherited(base) subclasses << base end - include PermalinkFu + extend PermalinkFu::PluginMethods attr_accessor :id attr_accessor :title attr_accessor :extra