Module: FeatureBox::Generators::GeneratorBase

Includes:
Rails::Generators::Migration
Included in:
ExistingGenerator, InitializerGenerator, MigrationsGenerator, StandaloneGenerator
Defined in:
lib/generators/feature_box/generator_base.rb

Overview

Helper methods

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(clazz) ⇒ Object



20
21
22
23
24
# File 'lib/generators/feature_box/generator_base.rb', line 20

def self.included clazz 
  clazz.source_root File.expand_path("../templates", __FILE__)
  clazz.extend include Rails::Generators::Migration::ClassMethods
  clazz.extend ClassMethods
end

Instance Method Details

#copy_migrations(patterns) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/generators/feature_box/generator_base.rb', line 26

def copy_migrations patterns
  model_name = @model_name || "User"
  Find.find(File.expand_path("../templates/migrations", __FILE__)) do |path|
    patterns.each do |pattern|
      if pattern.match(path)
        migration_template path, 'db/migrate/'+(File.basename(path,".rb"))[3..-1].gsub(/{model_name}/,model_name.tableize.gsub(/\//,''))
      end
    end
  end
end

#trim(str) ⇒ Object



37
38
39
# File 'lib/generators/feature_box/generator_base.rb', line 37

def trim str
  (str.gsub /^[\s]*([^\s])/m, '\1')
end

#trim_f(str) ⇒ Object



41
42
43
# File 'lib/generators/feature_box/generator_base.rb', line 41

def trim_f str
  (str.gsub /^[\s]*\|/m, '')
end