Class: ActiveRecord::Generators::BillableGenerator
- Inherits:
-
Base
- Object
- Base
- ActiveRecord::Generators::BillableGenerator
- Includes:
- Pay::Generators::OrmHelpers
- Defined in:
- lib/generators/active_record/billable_generator.rb
Instance Method Summary collapse
- #copy_pay_billable_migration ⇒ Object
-
#inject_pay_billable_content ⇒ Object
If the file already contains the contents, the user will receive this warning:.
Instance Method Details
#copy_pay_billable_migration ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/generators/active_record/billable_generator.rb', line 12 def copy_pay_billable_migration if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name)) migration_template "billable_migration.rb", "#{migration_path}/add_pay_billable_to_#{table_name}.rb", migration_version: migration_version else say "#{model_path} does not exist.", :red say "⚠️ Make sure the #{name} model exists before running this generator." end end |
#inject_pay_billable_content ⇒ Object
If the file already contains the contents, the user will receive this warning:
File unchanged! The supplied flag value not found!
This can be ignored as it just means the contents already exist and the file is unchanged. Thor will be updated to improve this message: github.com/rails/thor/issues/706
27 28 29 30 31 32 33 34 35 |
# File 'lib/generators/active_record/billable_generator.rb', line 27 def inject_pay_billable_content return unless model_exists? 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) end |