File: simple_captcha_generator.rb

package info (click to toggle)
ruby-simple-captcha2 0.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 168 kB
  • sloc: ruby: 589; makefile: 2
file content (29 lines) | stat: -rw-r--r-- 836 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
require 'rails/generators'

class SimpleCaptchaGenerator < Rails::Generators::Base
  argument :template_format, :type => :string, :default => 'erb'
  include Rails::Generators::Migration

  def self.source_root
    @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates/'))
  end

  def self.next_migration_number(dirname)
    Time.now.strftime("%Y%m%d%H%M%S")
  end

  def create_partial
    template "partial.#{template_format}", File.join('app/views', 'simple_captcha', "_simple_captcha.#{template_format}")
  end

  def create_captcha_migration
    migration_template migration_file, File.join('db/migrate', "create_simple_captcha_data.rb")
  end

  private

  def migration_file
    return "migration_sequel.rb" if defined?(Sequel)
    Rails::VERSION::MAJOR > 4 ? "migration5.rb" : "migration.rb"
  end
end