Add a scope method prefix configuration option to avoid namespace collisions (e.g., scope_ or s_ for brevity):
module Mongoid
module Enum
class Configuration
attr_accessor :field_name_prefix
attr_accessor :scope_method_prefix
def initialize
self.field_name_prefix = "_"
self.scope_method_prefix = "s_"
end
end
def self.configuration
@configuration ||= Configuration.new
end
def self.configure
yield(configuration) if block_given?
end
end
end
In the process of converting a project from using
symbolize/mongoid
tomongoid-enum
, I had a model that declares the following enum:The enum declaration creates scope methods for the enum values:
So now mongoid-enum has overridden the
new
method, which blows up calls toMyModel.create
orMyModel.create!
.There are a couple of ways this can be fixed (ideally, both could be implemented).
Add a new option to disable scopes for an enum:
scope_
ors_
for brevity):