Class: CustomCaptcha::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Generators::Utils::InstanceMethods
Defined in:
lib/generators/custom_captcha/install/install_generator.rb

Instance Method Summary collapse

Methods included from Generators::Utils::InstanceMethods

#display

Instance Method Details

#create_initializerObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/generators/custom_captcha/install/install_generator.rb', line 11

def create_initializer
  data_custom_captcha_rb = %Q/
CustomCaptcha.configure do |config|
config.image_columns  = 120
config.image_rows     = 40
config.image_style    = "simply_blue"
config.text_range     = ("a".."z").to_a
config.text_length    = 5
config.images_path    = Rails.root.join("public", "system", "captcha_images").to_s
config.enable         = true
config.salt           = "#{ SecureRandom.hex(20) }"
end
  /
  initializer "custom_captcha.rb", data_custom_captcha_rb
end

#create_localeObject



27
28
29
# File 'lib/generators/custom_captcha/install/install_generator.rb', line 27

def create_locale
  copy_file "../../../../../config/locales/custom_captcha.en.yml", "config/locales/custom_captcha.en.yml"
end

#create_viewsObject



31
32
33
34
35
36
# File 'lib/generators/custom_captcha/install/install_generator.rb', line 31

def create_views
  filename_pattern = File.expand_path("../../../../../app/views/custom_captcha/captcha_styles/*", __FILE__)
  Dir[filename_pattern].each do |f|
    copy_file f, "app/views/custom_captcha/captcha_styles/#{File.basename f}"
  end
end

#show_readmeObject



44
45
46
47
# File 'lib/generators/custom_captcha/install/install_generator.rb', line 44

def show_readme
  display "Succeed! custom_captcha has been installed."
  readme("README")
end

#test_rakesObject



38
39
40
41
42
# File 'lib/generators/custom_captcha/install/install_generator.rb', line 38

def test_rakes
  display "test generate and clear images..."
  rake("custom_captcha:generate_images[1]")
  rake("custom_captcha:clear_images")
end