Class: Auth::Generators::MigrationGenerator

Inherits:
Rails::Generator::NamedBase
  • Object
show all
Defined in:
lib/auth/generators/migration_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, options = {}) ⇒ MigrationGenerator

Returns a new instance of MigrationGenerator.



4
5
6
7
8
# File 'lib/auth/generators/migration_generator.rb', line 4

def initialize(model, options = {})
  @model = model
  args = [ model.name ]
  super(args, options)
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



2
3
4
# File 'lib/auth/generators/migration_generator.rb', line 2

def model
  @model
end

Instance Method Details

#manifestObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/auth/generators/migration_generator.rb', line 10

def manifest
  record do |m|
    m.directory "db/migrate"
    mg_version = 0
    Auth.behavior_classes.each do |behavior|
      behavior.migrations.each do |file_name|
        fn_with_ext = file_name[/\.([^\.]+)$/] ? file_name : "#{file_name}.rb"
        mg_version += 1
        mg_version_s = mg_version.to_s.rjust(3, '0')
        m.template File.join("migrations", fn_with_ext), File.join("db/migrate/#{mg_version_s}_#{fn_with_ext}")
      end
    end
  end
end

#specObject



29
30
31
# File 'lib/auth/generators/migration_generator.rb', line 29

def spec
  @spec ||= Rails::Generator::Spec.new("sparkly_migration", File.join(Auth.path, "auth/generators"), nil)
end

#table_nameObject



25
26
27
# File 'lib/auth/generators/migration_generator.rb', line 25

def table_name
  model && model.target ? model.target.table_name : super
end