Sha256: 96b4c5a9facd2a1b82a5d40f33f55fe9ad2d46f81a71314c6a543eea4b67adb7

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

require 'generators/lookylu/base_generator'

module Lookylu
  module Generators
    class StateGenerator < Lookylu::Generators::BaseGenerator
      include Rails::Generators::Migration
      source_root File.expand_path('../templates', __FILE__)
      desc 'Build the state LU items'

      class_option :model, :type => :boolean, :default => true, :desc => "Generate a default model object."

      def generate_migration
        if Dir.glob(migration_location('*')).empty?
          template "states_migration.erb", migration_location(next_migration_number)
        end
      end

      def generate_model
        if options.model
          if Dir.glob(model_location).empty?
            template 'states_model.erb', model_location
          end
        end
      end

      private

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

        def migration_location version
          "db/migrate/#{version}_lookylu_create_#{plural_name}.rb"
        end

        def model_location
          "app/models/#{model_name}.rb"
        end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
looky-lu-0.0.2 lib/generators/lookylu/state_generator.rb