Class: FeedbackandscreencapGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object

:nodoc:



11
12
13
14
15
16
17
# File 'lib/rails/generators/feedbackandscreencap/feedbackandscreencap_generator.rb', line 11

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



7
8
9
# File 'lib/rails/generators/feedbackandscreencap/feedbackandscreencap_generator.rb', line 7

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

Instance Method Details

#copy_assetsObject



52
53
54
55
# File 'lib/rails/generators/feedbackandscreencap/feedbackandscreencap_generator.rb', line 52

def copy_assets
  directory '../../../../../app/assets/javascripts/', 'app/assets/javascripts/'
  directory '../../../../../app/assets/stylesheets/', 'app/assets/stylesheets/'
end

#copy_controllerObject



44
45
46
# File 'lib/rails/generators/feedbackandscreencap/feedbackandscreencap_generator.rb', line 44

def copy_controller
  copy_file '../../../../../app/controllers/feedback_and_screencaps_controller.rb', 'app/controllers/feedback_and_screencaps_controller.rb'
end

#copy_modelObject



40
41
42
# File 'lib/rails/generators/feedbackandscreencap/feedbackandscreencap_generator.rb', line 40

def copy_model
  copy_file '../../../../../app/models/feedback_and_screencap.rb', 'app/models/feedback_and_screencap.rb'
end

#copy_viewsObject



48
49
50
# File 'lib/rails/generators/feedbackandscreencap/feedbackandscreencap_generator.rb', line 48

def copy_views
   directory '../../../../../app/views/feedback_and_screencaps/', 'app/views/feedback_and_screencaps/'
end

#create_migration_fileObject

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



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rails/generators/feedbackandscreencap/feedbackandscreencap_generator.rb', line 21

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 = Tempfile.new('foo')
  tmp.write migration
  tmp.close

  migration_template tmp.path,'db/migrate/create_feedbackandscreencap_tables.rb'

end