Browse files

remove the last bits of self.included and self.extended extensions

  • Loading branch information...
1 parent bdedce0 commit cc76754d11de5d5457171a7bb50904f70fa8ae9e @technoweenie committed Sep 25, 2008
Showing with 15 additions and 18 deletions.
  1. +1 −1 init.rb
  2. +13 −16 lib/permalink_fu.rb
  3. +1 −1 test/permalink_fu_test.rb
View
2 init.rb
@@ -1 +1 @@
-ActiveRecord::Base.send :include, PermalinkFu
+ActiveRecord::Base.extend PermalinkFu::PluginMethods
View
29 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
View
2 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

0 comments on commit cc76754

Please sign in to comment.