Skip to content

Commit

Permalink
remove the last bits of self.included and self.extended extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
technoweenie committed Sep 25, 2008
1 parent bdedce0 commit cc76754
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion init.rb
@@ -1 +1 @@
ActiveRecord::Base.send :include, PermalinkFu
ActiveRecord::Base.extend PermalinkFu::PluginMethods
29 changes: 13 additions & 16 deletions lib/permalink_fu.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/permalink_fu_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit cc76754

Please sign in to comment.