Class: Noticed::Generators::ModelGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- Noticed::Generators::ModelGenerator
- Includes:
- Rails::Generators::ResourceHelpers
- Defined in:
- lib/generators/noticed/model_generator.rb
Instance Method Summary collapse
- #add_not_nullable ⇒ Object
- #add_noticed_model ⇒ Object
- #done ⇒ Object
- #generate_notification ⇒ Object
Instance Method Details
#add_not_nullable ⇒ Object
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_model ⇒ Object
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 |
#done ⇒ Object
34 35 36 |
# File 'lib/generators/noticed/model_generator.rb', line 34 def done readme "README" if behavior == :invoke end |
#generate_notification ⇒ Object
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 |