Sha256: d7e9b28a5f6183e1dc7956b09a21e21e4675a175354d1e481b4b1a56173e4e83

Contents?: true

Size: 1.4 KB

Versions: 8

Compression:

Stored size: 1.4 KB

Contents

require 'rails/generators/active_record'
require 'generators/release_notes/orm_helpers'

module ActiveRecord
  module Generators
    class ReleaseNotesGenerator < ActiveRecord::Generators::Base
      argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"

      include ReleaseNotes::Generators::OrmHelpers
      source_root File.expand_path("../templates", __FILE__)

      def copy_release_notes_migration
        if (behavior == :invoke && model_exists?)
          raise "#{table_name} already exists..."
        else
          migration_template "release_notes_migration.rb", "db/migrate/release_notes_create_#{table_name}.rb"
        end
      end

      def generate_model
        invoke "active_record:model", [name], :migration => false unless model_exists? && behavior == :invoke
      end

      def inject_release_notes_content
        content = release_notes_model_contents

        class_path = if namespaced?
          class_name.to_s.split("::")
        else
          [class_name]
        end

        indent_depth = class_path.size - 1
        content = content.split("\n").map { |line| " " * indent_depth + line }.join("\n") << "\n"
      
        inject_into_class(model_path, class_path.last, content) if model_exists?
      end

      def migration_data
<<RUBY
      t.text :markdown,     :null => false
      t.string :version,    :null => false
RUBY
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
release_notes-1.0.4 lib/generators/active_record/release_notes_generator.rb
release_notes-1.0.3 lib/generators/active_record/release_notes_generator.rb
release_notes-1.0.1 lib/generators/active_record/release_notes_generator.rb
release_notes-1.0.0 lib/generators/active_record/release_notes_generator.rb
release_notes-0.5.1 lib/generators/active_record/release_notes_generator.rb
release_notes-0.4.0 lib/generators/active_record/release_notes_generator.rb
release_notes-0.3.4 lib/generators/active_record/release_notes_generator.rb
release_notes-0.3.3 lib/generators/active_record/release_notes_generator.rb