Assuming the following module which allows to add acts_as_timeable functionality to an arbitrary model.
module Timeable
module ActsAsTimeable
extend ActiveSupport::Concern
module ClassMethods
def acts_as_timeable(options ={})
...
end
end
end
end
ActiveRecord::Base.send :include, Timeable::ActsAsTimeable
According to the last line, acts_as_timeable class method is made available in ActiveRecord::Base. So any model extending form ActiveRecord::Base will return true when calling Model.respond_to?(:acts_as_timeable) => true.
How can I detect whether a model actually acts_as_timeable based on whether a line starting with acts_as_timeable…
class Model < ActiveRecord::Base
acts_as_timeable
end
…(and maybe some options) has been added to the model or not?
I think that the simplest way to do this is to set this state on the model class itself.
In
acts_as_timetableyou can set a class variable, and expose it through an accessor, like this:Then you can check simply with
MyModel.timeable?