Class: IonicNotification::Generators::ModelGenerator

Inherits:
ActiveRecord::Generators::Base
  • Object
show all
Includes:
OrmHelpers
Defined in:
lib/generators/ionic_notification/model/model_generator.rb

Instance Method Summary collapse

Methods included from OrmHelpers

#model_contents

Instance Method Details

#copy_migrationObject



14
15
16
# File 'lib/generators/ionic_notification/model/model_generator.rb', line 14

def copy_migration
  migration_template "migration.rb", "db/migrate/add_device_tokens_to_#{table_name}.rb"
end

#inject_ionic_notification_contentObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/generators/ionic_notification/model/model_generator.rb', line 18

def inject_ionic_notification_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)
end