Class: WeixinRailsMiddleware::Generators::MigrationGenerator
- Inherits:
-
ActiveRecord::Generators::Base
- Object
- ActiveRecord::Generators::Base
- WeixinRailsMiddleware::Generators::MigrationGenerator
- Defined in:
- lib/generators/weixin_rails_middleware/migration_generator.rb
Instance Method Summary collapse
Instance Method Details
#create_migration_file ⇒ Object
9 10 11 12 13 |
# File 'lib/generators/weixin_rails_middleware/migration_generator.rb', line 9 def create_migration_file if !migration_exists?(table_name) migration_template "add_weixin_secret_key_and_weixin_token_migration.rb", "db/migrate/add_weixin_secret_key_and_weixin_token_to_#{plural_name}.rb" end end |
#inject_model_content ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/generators/weixin_rails_middleware/migration_generator.rb', line 15 def inject_model_content content = <<-CONTENT # It will auto generate weixin token and secret include WeixinRailsMiddleware::AutoGenerateWeixinTokenSecretKey CONTENT class_path = if namespaced? class_name.to_s.split("::") else [class_name] end indent_depth = class_path.size - 1 content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n" inject_into_class(model_path, class_path.last, content) if model_exists? end |