Sha256: c57ec5c0d4382918278dc827612aa47aeb19c897a4c56a4736c5a611c424fc81

Contents?: true

Size: 861 Bytes

Versions: 2

Compression:

Stored size: 861 Bytes

Contents

require 'rails/generators'
require 'rails/generators/migration'

module PersistentSettings
  class CreateGenerator < ::Rails::Generators::Base
    include ::Rails::Generators::Migration

    argument :class_name, :type => :string
    argument :verbose, :type => :numeric, :default => 1

    source_root File.expand_path('../templates', __FILE__)

    def create_model
      @klass_name = class_name.classify
      template 'model.rb.erb', "models/#{class_name}.rb", :verbose => (verbose == 1)
    end

    def create_migration
      @table_name = class_name.pluralize.gsub("/", "_")
      @migration_class = @table_name.camelize
      migration_template "create_table.rb.erb", "db/migrate/create_#{@table_name}_table.rb", :verbose => (verbose == 1)
    end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
persistent_settings-1.4.0 lib/generators/persistent_settings/create_generator.rb
persistent_settings-1.3.0 lib/generators/persistent_settings/create_generator.rb