Class: Wcc::ModelGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Wcc::ModelGenerator
- Defined in:
- lib/generators/wcc/model_generator.rb
Constant Summary collapse
- VALID_MODELS =
%w[menu page].freeze
Instance Method Summary collapse
- #create_model_migration ⇒ Object
- #drop_model_overrides_in_app_models ⇒ Object
- #ensure_initializer_exists ⇒ Object
- #ensure_migration_tools_installed ⇒ Object
- #ensure_wrapper_script_in_bin_dir ⇒ Object
-
#initialize ⇒ ModelGenerator
constructor
A new instance of ModelGenerator.
Constructor Details
#initialize ⇒ ModelGenerator
Returns a new instance of ModelGenerator.
10 11 12 13 14 15 16 |
# File 'lib/generators/wcc/model_generator.rb', line 10 def initialize(*) super return if VALID_MODELS.include?(singular) raise ArgumentError, "Model must be #{VALID_MODELS.to_sentence}" end |
Instance Method Details
#create_model_migration ⇒ Object
67 68 69 70 |
# File 'lib/generators/wcc/model_generator.rb', line 67 def create_model_migration copy_file "#{singular}/generated_add_#{plural}.ts", "db/migrate/#{}01_generated_add_#{plural}.ts" end |
#drop_model_overrides_in_app_models ⇒ Object
72 73 74 |
# File 'lib/generators/wcc/model_generator.rb', line 72 def drop_model_overrides_in_app_models directory "#{singular}/models", 'app/models' end |
#ensure_initializer_exists ⇒ Object
61 62 63 64 65 |
# File 'lib/generators/wcc/model_generator.rb', line 61 def ensure_initializer_exists return if inside('config/initializers') { File.exist?('wcc_contentful.rb') } copy_file 'wcc_contentful.rb', 'config/initializers/wcc_contentful.rb' end |
#ensure_migration_tools_installed ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/generators/wcc/model_generator.rb', line 18 def ensure_migration_tools_installed in_root do run 'npm init -y' unless File.exist?('package.json') package = JSON.parse(File.read('package.json')) deps = package['dependencies'] unless deps.try(:[], 'contentful-migration-cli').present? run 'npm install --save watermarkchurch/migration-cli ts-node typescript contentful-export' end end end |
#ensure_wrapper_script_in_bin_dir ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/generators/wcc/model_generator.rb', line 30 def ensure_wrapper_script_in_bin_dir unless inside('bin') { File.exist?('contentful') } copy_file 'contentful_shell_wrapper', 'bin/contentful' end if inside('bin') { File.exist?('release') } release = inside('bin') { File.read('release') } unless release.include?('contentful migrate') insert_into_file('bin/release', after: 'bundle exec rake db:migrate') do <<~HEREDOC DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" $DIR/contentful migrate -y HEREDOC end end else copy_file 'release', 'bin/release' end if in_root { File.exist?('Procfile') } procfile = in_root { File.read('Procfile') } unless procfile.include?('release:') insert_into_file('Procfile') do 'release: bin/release' end end else copy_file 'Procfile' end end |