Class: ActiveRecord::Generators::NotificationHubGenerator
- Inherits:
-
Base
- Object
- Base
- ActiveRecord::Generators::NotificationHubGenerator
- Defined in:
- lib/generators/active_record/notification_hub_generator.rb
Instance Method Summary collapse
- #create_models_and_migrations ⇒ Object
- #inject_content_to_user ⇒ Object
- #migration_version ⇒ Object
- #migrations_path ⇒ Object
- #models_path ⇒ Object
- #rails5? ⇒ Boolean
Instance Method Details
#create_models_and_migrations ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/generators/active_record/notification_hub_generator.rb', line 11 def create_models_and_migrations template "models/subscription.rb", "#{models_path}/notification_hub/subscription.rb", rails5?: rails5? migration_template "migrations/subscriptions.rb", "#{migrations_path}/create_notification_hub_subscriptions.rb", migration_version: migration_version template "models/device.rb", "#{models_path}/notification_hub/device.rb", rails5?: rails5? migration_template "migrations/devices.rb", "#{migrations_path}/create_notification_hub_devices.rb", migration_version: migration_version template "models/subscription_device.rb", "#{models_path}/notification_hub/subscription_device.rb", rails5?: rails5? migration_template "migrations/subscription_devices.rb", "#{migrations_path}/create_notification_hub_subscription_devices.rb", migration_version: migration_version end |
#inject_content_to_user ⇒ Object
22 23 24 25 26 27 |
# File 'lib/generators/active_record/notification_hub_generator.rb', line 22 def inject_content_to_user content = "has_many :notification_hub_subscriptions, class_name: 'NotificationHub::Subscription', dependent: :destroy\nhas_many :notification_hub_devices, class_name: 'NotificationHub::Device', dependent: :destroy" content = content.split("\n").map { |line| " " + line } .join("\n") << "\n" inject_into_class("#{models_path}/#{association_model}.rb", association_model.classify, content) end |
#migration_version ⇒ Object
33 34 35 36 37 |
# File 'lib/generators/active_record/notification_hub_generator.rb', line 33 def migration_version if rails5? "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" end end |
#migrations_path ⇒ Object
39 40 41 |
# File 'lib/generators/active_record/notification_hub_generator.rb', line 39 def migrations_path @migrations_path ||= File.join("db", "migrate") end |
#models_path ⇒ Object
43 44 45 |
# File 'lib/generators/active_record/notification_hub_generator.rb', line 43 def models_path @models_path ||= File.join("app", "models") end |
#rails5? ⇒ Boolean
29 30 31 |
# File 'lib/generators/active_record/notification_hub_generator.rb', line 29 def rails5? Rails.version.start_with? '5' end |