Class: FrameyGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/rails/generators/framey/framey_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object

:nodoc:



15
16
17
18
19
20
21
# File 'lib/rails/generators/framey/framey_generator.rb', line 15

def self.next_migration_number(dirname) #:nodoc:
  if ActiveRecord::Base.timestamped_migrations
    Time.now.utc.strftime("%Y%m%d%H%M%S")
  else
    "%.3d" % (current_migration_number(dirname) + 1)
  end
end

.source_rootObject



10
11
12
13
# File 'lib/rails/generators/framey/framey_generator.rb', line 10

def self.source_root
  sources = File.join(File.dirname(__FILE__), 'templates')
  
end

Instance Method Details

#copy_controllersObject



75
76
77
# File 'lib/rails/generators/framey/framey_generator.rb', line 75

def copy_controllers
  copy_file '../../../../../app/controllers/framey/videos_controller.rb', 'app/controllers/framey/videos_controller.rb'
end

#copy_initializer_fileObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rails/generators/framey/framey_generator.rb', line 46

def copy_initializer_file

  if self.api_key and self.api_secret
    f = File.open File.join(File.dirname(__FILE__), 'templates', 'initializer.rb')
    initializer = f.read; f.close
  
    initializer.gsub!(/API_KEY_VALUE/, self.api_key)
    initializer.gsub!(/API_SECRET_VALUE/, self.api_secret)
  
    tmp = File.open "tmp/~initializer_ready.rb", "w"
    tmp.write initializer
    tmp.close
  
    copy_file  '../../../tmp/~initializer_ready.rb',
                        'config/initializers/framey.rb'
    remove_file 'tmp/~initializer_ready.rb'
  else
    copy_file 'initializer.rb', 'config/initializers/framey.rb'
  end

end

#copy_modelsObject



79
80
81
# File 'lib/rails/generators/framey/framey_generator.rb', line 79

def copy_models
  copy_file '../../../../../app/models/framey/video.rb', 'app/models/framey/video.rb'
end

#copy_viewsObject



68
69
70
71
72
73
# File 'lib/rails/generators/framey/framey_generator.rb', line 68

def copy_views
  copy_file '../../../../../app/views/framey/videos/index.html.erb', 'app/views/framey/videos/index.html.erb'
  copy_file '../../../../../app/views/framey/videos/new.html.erb', 'app/views/framey/videos/new.html.erb'
  copy_file '../../../../../app/views/framey/videos/show.html.erb', 'app/views/framey/videos/show.html.erb'
  copy_file '../../../../../app/views/layouts/framey.html.erb', 'app/views/layouts/framey.html.erb'
end

#create_migration_fileObject

Every method that is declared below will be automatically executed when the generator is run



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rails/generators/framey/framey_generator.rb', line 26

def create_migration_file
  f = File.open File.join(File.dirname(__FILE__), 'templates', 'schema.rb')
  schema = f.read; f.close
  
  schema.gsub!(/ActiveRecord::Schema.*\n/, '')
  schema.gsub!(/^end\n*$/, '')

  f = File.open File.join(File.dirname(__FILE__), 'templates', 'migration.rb')
  migration = f.read; f.close
  migration.gsub!(/SCHEMA_AUTO_INSERTED_HERE/, schema)
  
  tmp = File.open "tmp/~migration_ready.rb", "w"
  tmp.write migration
  tmp.close

  migration_template  '../../../tmp/~migration_ready.rb',
                      'db/migrate/create_framey_tables.rb'
  remove_file 'tmp/~migration_ready.rb'
end