I’ve got a plugin that is really a collection of plugins, and I want
one plugin to see methods from another.
I’ve tried to simplify what I’ve done and what I’m seeing
So my (simplified) file structure looks like this:
acts_as_foobar/
- init.rb
- lib/
acts_as_foobar.rb
foo.rb
bar.rb
init.rb:
require ‘acts_as_foobar.rb’
acts_as_foobar.rb:
require ‘foo’
require ‘bar’
foo.rb:
module Foo
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def acts_as_foo
class_eval do
extend Foo::SingletonMethods
end
end
end
module SingletonMethods
def static_foo_method
...do something foo-ish here...
end
end
end
ActiveRecord::Base.send(:include, Foo)
bar.rb:
module Bar
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def acts_as_bar
include Bar::InstanceMethods
end
end
module InstanceMethods
def instance_bar_method
X.static_foo_method
end
end
end
ActiveRecord::Base.send(:include, Bar)
Now, I have two model classes, X and Y
X.rb
class X < ActiveRecord::Base
acts_as_foo
end
Y.rb
class Y < ActiveRecord::Base
acts_as_bar
end
Now if I try this:
Y.find(1).instance_bar_method
I’ll get an error like this:
‘undefined method `static_foo_method’ for Foo:Module
(NoMethodError)
But I can call
X.static_foo_method
and get the results I expect.
(I know this use of a plugin may not be optimal)
Any clues as to how I can get this work?
Thanks,
-kevin