Sha256: 6b75b9a15a55585aee39f26acb20d6e4e4d353bbe2f640862366920cfd02bb17

Contents?: true

Size: 1.28 KB

Versions: 19

Compression:

Stored size: 1.28 KB

Contents

require 'rails/generators/migration'

module Cable
  module Generators
      class MediaGenerator < Rails::Generators::NamedBase
        include Rails::Generators::Migration
        
         source_root File.expand_path("../templates", __FILE__)
         desc "Generates a Cable Menu with the given NAME (if one does not exist) plus a migration file"
         
         class_option :install, :type => :boolean, :default => false
         
         def create_table
           if options.install?
             migration_template 'migration.rb', "db/migrate/create_cable_media_assets.rb" 
           end
         end
         
         def create_model
           template 'model.rb' , "app/models/#{model_name}.rb"
         end
         
         # Implement the required interface for Rails::Generators::Migration.
         # taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
         def self.next_migration_number(dirname)
          if ActiveRecord::Base.timestamped_migrations
            Time.now.utc.strftime("%Y%m%d%H%M%S")
          else
            "%.3d" % (current_migration_number(dirname) + 1)
          end
         end
         
         private

         def model_name
           class_name.underscore
         end
         
      end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
cable-0.9.17 lib/generators/cable/media/media_generator.rb
cable-0.9.16 lib/generators/cable/media/media_generator.rb
cable-0.9.15 lib/generators/cable/media/media_generator.rb
cable-0.9.14 lib/generators/cable/media/media_generator.rb
cable-0.9.13 lib/generators/cable/media/media_generator.rb
cable-0.9.12 lib/generators/cable/media/media_generator.rb
cable-0.9.11 lib/generators/cable/media/media_generator.rb
cable-0.9.10 lib/generators/cable/media/media_generator.rb
cable-0.9.9 lib/generators/cable/media/media_generator.rb
cable-0.9.8 lib/generators/cable/media/media_generator.rb
cable-0.9.6 lib/generators/cable/media/media_generator.rb
cable-0.9.5 lib/generators/cable/media/media_generator.rb
cable-0.9.4 lib/generators/cable/media/media_generator.rb
cable-0.9.3 lib/generators/cable/media/media_generator.rb
cable-0.9.1 lib/generators/cable/media/media_generator.rb
cable-0.9.0 lib/generators/cable/media/media_generator.rb
cable-0.8.6 lib/generators/cable/media/media_generator.rb
cable-0.8.5 lib/generators/cable/media/media_generator.rb
cable-0.8.4 lib/generators/cable/media/media_generator.rb