class ActiveRecord::Generators::ZettoGenerator
Public Instance Methods
add_zetto_migration()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# File lib/generators/active_record/zetto_generator.rb, line 50 def migration_version if rails5? "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" end end
rails5?()
click to toggle source
# File lib/generators/active_record/zetto_generator.rb, line 46 def rails5? Rails.version.start_with? '5' end