At the moment, I save each option in my own class attribute, but this leads to hard-to-read code when I need to access the passed parameters from instance methods.
For example, if I pass the column name as a parameter, I should use self.send(self.class.path_finder_column)to get the column value from the instance method.
Notice that I prefix the class attribute with the name of my plugin to prevent name clashes.
Here is a simple example of a plugin code that is passed a parameter column, which is then accessed from an instance method set_path. Could simplifications for getters / setters be more readable?
module PathFinder
def path_finder(options = {})
send :include, InstanceMethods
self.cattr_accessor :path_finder_column
self.path_finder_column = options[:column]
module InstanceMethods
def set_path
self.send(self.class.path_finder_column + '=', 'some value')
self.send(self.class.path_finder_column)
end
end
end
end
ActiveRecord::Base.send :extend, PathFinder