class DeviseAuthy::Generators::InstallGenerator

Install Generator

Public Instance Methods

add_configs() click to toggle source
# File lib/generators/devise_authy/install_generator.rb, line 14
def add_configs
  inject_into_file "config/initializers/devise.rb", "\n" +
  "  # ==> Devise Authy Authentication Extension\n" +
  "  # How long should the user's device be remembered for.\n" +
  "  # config.authy_remember_device = 1.month\n\n" +
  "  # Should Authy OneTouch be enabled?\n" +
  "  # config.authy_enable_onetouch = false\n\n" +
  "  # Should generating QR codes for other authenticator apps be enabled?\n" +
  "  # Note: you need to enable this in your Twilio console.\n" +
  "  # config.authy_enable_qr_code = false\n\n", :after => "Devise.setup do |config|\n"
end
add_initializer() click to toggle source
# File lib/generators/devise_authy/install_generator.rb, line 26
def add_initializer
  initializer("authy.rb") do
    "Authy.api_key = ENV[\"AUTHY_API_KEY\"]\n" \
    "Authy.api_uri = \"https://api.authy.com/\""
  end
end
copy_assets() click to toggle source
# File lib/generators/devise_authy/install_generator.rb, line 49
def copy_assets
  if options.sass?
    copy_file '../../../app/assets/stylesheets/devise_authy.sass', 'app/assets/stylesheets/devise_authy.sass'
  else
    copy_file '../../../app/assets/stylesheets/devise_authy.css', 'app/assets/stylesheets/devise_authy.css'
  end
  copy_file '../../../app/assets/javascripts/devise_authy.js', 'app/assets/javascripts/devise_authy.js'
end
copy_locale() click to toggle source
# File lib/generators/devise_authy/install_generator.rb, line 33
def copy_locale
  copy_file "../../../config/locales/en.yml", "config/locales/devise.authy.en.yml"
end
copy_views() click to toggle source
# File lib/generators/devise_authy/install_generator.rb, line 37
def copy_views
  if options.haml?
    copy_file '../../../app/views/devise/enable_authy.html.haml', 'app/views/devise/devise_authy/enable_authy.html.haml'
    copy_file '../../../app/views/devise/verify_authy.html.haml', 'app/views/devise/devise_authy/verify_authy.html.haml'
    copy_file '../../../app/views/devise/verify_authy_installation.html.haml', 'app/views/devise/devise_authy/verify_authy_installation.html.haml'
  else
    copy_file '../../../app/views/devise/enable_authy.html.erb', 'app/views/devise/devise_authy/enable_authy.html.erb'
    copy_file '../../../app/views/devise/verify_authy.html.erb', 'app/views/devise/devise_authy/verify_authy.html.erb'
    copy_file '../../../app/views/devise/verify_authy_installation.html.erb', 'app/views/devise/devise_authy/verify_authy_installation.html.erb'
  end
end
inject_assets_in_layout() click to toggle source
# File lib/generators/devise_authy/install_generator.rb, line 58
      def inject_assets_in_layout
        {
          :haml => {
            :before => %r{%body\s*$},
            :content => %@
    =javascript_include_tag "https://www.authy.com/form.authy.min.js"
    =stylesheet_link_tag "https://www.authy.com/form.authy.min.css"
@
          },
          :erb => {
            :before => %r{\s*<\/\s*head\s*>\s*},
            :content => %@
  <%=javascript_include_tag "https://www.authy.com/form.authy.min.js" %>
  <%=stylesheet_link_tag "https://www.authy.com/form.authy.min.css" %>
@
          }
        }.each do |extension, opts|
          file_path = File.join(destination_root, "app", "views", "layouts", "application.html.#{extension}")
          if File.exist?(file_path) && !File.read(file_path).include?("form.authy.min.js")
            inject_into_file(file_path, opts.delete(:content), opts)
          end
        end
      end