Class: Noticed::Generators::ModelGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
Rails::Generators::ResourceHelpers
Defined in:
lib/generators/noticed/model_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_not_nullableObject



25
26
27
28
29
30
31
32
# File 'lib/generators/noticed/model_generator.rb', line 25

def add_not_nullable
  migration_path = Dir.glob(Rails.root.join("db/migrate/*")).max_by { |f| File.mtime(f) }

  # Force is required because null: false already exists in the file and Thor isn't smart enough to tell the difference
  insert_into_file migration_path, after: "t.string :type", force: true do
    ", null: false"
  end
end

#add_noticed_modelObject



21
22
23
# File 'lib/generators/noticed/model_generator.rb', line 21

def add_noticed_model
  inject_into_class model_path, class_name, "  include Noticed::Model\n"
end

#doneObject



34
35
36
# File 'lib/generators/noticed/model_generator.rb', line 34

def done
  readme "README" if behavior == :invoke
end

#generate_notificationObject



17
18
19
# File 'lib/generators/noticed/model_generator.rb', line 17

def generate_notification
  generate :model, name, "recipient:references{polymorphic}", "type", params_column, "read_at:datetime:index", *attributes
end