Class: ActiveRecord::Generators::PayGenerator
- Inherits:
-
Base
- Object
- Base
- ActiveRecord::Generators::PayGenerator
- Includes:
- Pay::Generators::OrmHelpers
- Defined in:
- lib/generators/active_record/pay_generator.rb
Instance Method Summary collapse
- #copy_pay_billable_migration ⇒ Object
- #inject_pay_billable_content ⇒ Object
- #migration_data ⇒ Object
- #migration_version ⇒ Object
- #rails5_and_up? ⇒ Boolean
Methods included from Pay::Generators::OrmHelpers
Instance Method Details
#copy_pay_billable_migration ⇒ Object
12 13 14 15 16 17 |
# File 'lib/generators/active_record/pay_generator.rb', line 12 def copy_pay_billable_migration if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name)) migration_template "migration.rb", "#{migration_path}/add_pay_billable_to_#{table_name}.rb", migration_version: migration_version end # TODO: Throw error here that model should already exist if it doesn't end |
#inject_pay_billable_content ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/generators/active_record/pay_generator.rb', line 19 def inject_pay_billable_content content = model_contents 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 |
#migration_data ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/generators/active_record/pay_generator.rb', line 34 def migration_data <<RUBY t.string :processor t.string :processor_id t.datetime :trial_ends_at t.string :card_type t.string :card_last4 t.string :card_exp_month t.string :card_exp_year t.text :extra_billing_info RUBY end |
#migration_version ⇒ Object
51 52 53 54 55 |
# File 'lib/generators/active_record/pay_generator.rb', line 51 def migration_version if rails5_and_up? "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" end end |
#rails5_and_up? ⇒ Boolean
47 48 49 |
# File 'lib/generators/active_record/pay_generator.rb', line 47 def rails5_and_up? Rails::VERSION::MAJOR >= 5 end |