Class: RubiGen::Commands::Base

### Home Classes Methods

### In Files

- lib/rubigen/commands.rb

### Parent

DelegateClass(RubiGen::Base)

### Methods

- #class_collisions
- #current_migration_number
- #dependency
- #existing_migrations
- #gsub_file
- #invoke!
- #migration_directory
- #migration_exists?
- #next_migration_number
- #next_migration_string
- #readme
- #write_manifest

### Files

- History.txt
- License.txt
- Manifest.txt
- Todo.txt
- README.txt
- index.txt
- version-raw.txt
- version.txt

### Class/Module Index

Quicksearch

- RubiGen
- RubiGen::AbstractGemSource
- RubiGen::Base
- RubiGen::Commands
- RubiGen::Commands::Base
- RubiGen::Commands::Create
- RubiGen::Commands::Destroy
- RubiGen::Commands::List
- RubiGen::Commands::RewindBase
- RubiGen::Commands::Update
- RubiGen::GemPathSource
- RubiGen::GeneratedAttribute
- RubiGen::GeneratorError
- RubiGen::GeneratorTestHelper
- RubiGen::Lookup
- RubiGen::Lookup::ClassMethods
- RubiGen::Manifest
- RubiGen::Options
- RubiGen::Options::ClassMethods
- RubiGen::PathFilteredSource
- RubiGen::PathSource
- RubiGen::Scripts
- RubiGen::Scripts::Base
- RubiGen::Scripts::Destroy
- RubiGen::Scripts::Generate
- RubiGen::Scripts::Update
- RubiGen::Source
- RubiGen::Spec
- RubiGen::UsageError
- Rubigen
- Rubigen::CLI
- Dir
- Object

No matching classes.

# RubiGen::Commands::Base

Generator commands delegate RubiGen::Base and implement a standard set of actions. Their behavior is defined by the way they respond to these actions: Create brings life; Destroy brings death; List passively observes.

Commands are invoked by replaying (or rewinding) the generator's manifest of actions. See RubiGen::Manifest and RubiGen::Base#manifest method that generator subclasses are required to override.

Commands allows generators to "plug in" invocation behavior, which corresponds to the GoF Strategy pattern.

### Public Instance Methods

class_collisions(*class_names) click to toggle source

Does nothing for all commands except Create.

    # File lib/rubigen/commands.rb, line 52
    def class_collisions(*class_names)
    end

dependency(generator_name, args, runtime_options = {}) click to toggle source

    # File lib/rubigen/commands.rb, line 45
    def dependency(generator_name, args, runtime_options = {})
      logger.dependency(generator_name) do
        self.class.new(instance(generator_name, args, full_options(runtime_options))).invoke!
      end
    end

invoke!() click to toggle source

Replay action manifest. RewindBase subclass rewinds manifest.

    # File lib/rubigen/commands.rb, line 40
    def invoke!
      manifest.replay(self)
      after_generate
    end

readme(*args) click to toggle source

Does nothing for all commands except Create.

    # File lib/rubigen/commands.rb, line 56
    def readme(*args)
    end

write_manifest() click to toggle source

Does nothing for all commands except Create.

    # File lib/rubigen/commands.rb, line 60
    def write_manifest
    end

### Protected Instance Methods

current_migration_number() click to toggle source

    # File lib/rubigen/commands.rb, line 64
    def current_migration_number
      Dir.glob("#{RAILS_ROOT}/#{@migration_directory}/[0-9]*_*.rb").inject(0) do |max, file_path|
        n = File.basename(file_path).split('_', 2).first.to_i
        if n > max then n else max end
      end
    end

existing_migrations(file_name) click to toggle source

    # File lib/rubigen/commands.rb, line 79
    def existing_migrations(file_name)
      Dir.glob("#{@migration_directory}/[0-9]*_*.rb").grep(/[0-9]+_#{file_name}.rb$/)
    end

gsub_file(relative_destination, regexp, *args, &block) click to toggle source

    # File lib/rubigen/commands.rb, line 95
    def gsub_file(relative_destination, regexp, *args, &block)
      path = destination_path(relative_destination)
      content = File.read(path).gsub(regexp, *args, &block)
      File.open(path, 'wb') { |file| file.write(content) }
    end

migration_directory(relative_path) click to toggle source

    # File lib/rubigen/commands.rb, line 75
    def migration_directory(relative_path)
      directory(@migration_directory = relative_path)
    end

migration_exists?(file_name) click to toggle source

    # File lib/rubigen/commands.rb, line 83
    def migration_exists?(file_name)
      not existing_migrations(file_name).empty?
    end

next_migration_number() click to toggle source

    # File lib/rubigen/commands.rb, line 71
    def next_migration_number
      current_migration_number + 1
    end

next_migration_string(padding = 3) click to toggle source

    # File lib/rubigen/commands.rb, line 87
    def next_migration_string(padding = 3)
      if ActiveRecord::Base.timestamped_migrations
        Time.now.utc.strftime("%Y%m%d%H%M%S")
      else
        "%.#{padding}d" % next_migration_number
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.