7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/mongoid/orderable/generators/lock_collection.rb', line 7
def generate(collection_name)
return unless collection_name
model_name = collection_name.to_s.singularize.classify
return if model_exists?(model_name)
::Mongoid::Orderable.class_eval <<~KLASS, __FILE__, __LINE__ + 1
module Models
class #{model_name}
include Mongoid::Document
include Mongoid::Timestamps::Updated::Short
store_in collection: :#{collection_name}
field :scope, type: String
index({ scope: 1 }, { unique: 1 })
index({ updated_at: 1 }, { expire_after_seconds: 86400 })
end
end
KLASS
end
|