Class: ActiveRecord::Generators::ZettoGenerator
- Inherits:
-
Base
- Object
- Base
- ActiveRecord::Generators::ZettoGenerator
- Includes:
- Zetto::Generators::OrmHelpers
- Defined in:
- lib/generators/active_record/zetto_generator.rb
Instance Method Summary collapse
- #add_zetto_migration ⇒ Object
- #generate_model ⇒ Object
- #inject_zetto_model_content ⇒ Object
- #migration_data ⇒ Object
- #migration_version ⇒ Object
- #rails5? ⇒ Boolean
Methods included from Zetto::Generators::OrmHelpers
Instance Method Details
#add_zetto_migration ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/generators/active_record/zetto_generator.rb', line 14 def add_zetto_migration if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name)) migration_template "migration_existing.erb", "db/migrate/add_zetto_to_#{table_name}.rb", migration_version: migration_version else migration_template "migration.erb", "db/migrate/zetto_create_#{table_name}.rb", migration_version: migration_version end end |
#generate_model ⇒ Object
22 23 24 |
# File 'lib/generators/active_record/zetto_generator.rb', line 22 def generate_model invoke "active_record:model", [name], migration: false unless model_exists? && behavior == :invoke end |
#inject_zetto_model_content ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/generators/active_record/zetto_generator.rb', line 26 def inject_zetto_model_content content = model_contents class_path = namespaced? ? class_name.to_s.split("::") : [class_name] 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 |
#migration_data ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/generators/active_record/zetto_generator.rb', line 37 def migration_data fields = {} key = Zetto::Config::Params.user_class_name fields[key] = ":string, :null => false, default: ''" key = Zetto::Config::Params.user_class_password fields[key] = ":string, :null => false, default: ''" fields end |
#migration_version ⇒ Object
50 51 52 53 54 |
# File 'lib/generators/active_record/zetto_generator.rb', line 50 def migration_version if rails5? "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" end end |
#rails5? ⇒ Boolean
46 47 48 |
# File 'lib/generators/active_record/zetto_generator.rb', line 46 def rails5? Rails.version.start_with? '5' end |