lib/generators/ahoy/messages/mongoid_generator.rb in ahoy_email-2.1.0 vs lib/generators/ahoy/messages/mongoid_generator.rb in ahoy_email-2.1.1
- old
+ new
@@ -4,16 +4,36 @@
module Generators
module Messages
class MongoidGenerator < Rails::Generators::Base
source_root File.join(__dir__, "templates")
+ class_option :encryption, type: :string
+ # deprecated
class_option :unencrypted, type: :boolean
def copy_templates
- if options[:unencrypted]
+ case encryption
+ when "lockbox"
+ template "mongoid_lockbox.rb", "app/models/ahoy/message.rb"
+ else
template "mongoid.rb", "app/models/ahoy/message.rb"
+ end
+ end
+
+ # TODO remove default
+ def encryption
+ case options[:encryption]
+ when "lockbox", "none"
+ options[:encryption]
+ when nil
+ if options[:unencrypted]
+ # TODO deprecation warning
+ "none"
+ else
+ "lockbox"
+ end
else
- template "mongoid_encrypted.rb", "app/models/ahoy/message.rb"
+ abort "Error: encryption must be lockbox or none"
end
end
end
end
end