Sha256: f0ccf97243a7814a077f357c1169f58ebfaa6dd02976296307937705b4d056bf

Contents?: true

Size: 1.22 KB

Versions: 5

Compression:

Stored size: 1.22 KB

Contents

require "rails/generators"

module Ahoy
  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
          case encryption
          when "lockbox"
            template "mongoid_lockbox.rb", "app/models/ahoy/message.rb", lockbox_method: lockbox_method
          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
            abort "Error: encryption must be lockbox or none"
          end
        end

        def lockbox_method
          if defined?(Lockbox::VERSION) && Lockbox::VERSION.to_i < 1
            "encrypts"
          else
            "has_encrypted"
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ahoy_email-2.4.0 lib/generators/ahoy/messages/mongoid_generator.rb
ahoy_email-2.3.1 lib/generators/ahoy/messages/mongoid_generator.rb
ahoy_email-2.3.0 lib/generators/ahoy/messages/mongoid_generator.rb
ahoy_email-2.2.0 lib/generators/ahoy/messages/mongoid_generator.rb
ahoy_email-2.1.3 lib/generators/ahoy/messages/mongoid_generator.rb