Class: Editables::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Editables::InstallGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/editables/generators/editables/install_generator.rb
Instance Method Summary collapse
- #add_editable_routes ⇒ Object
- #create_config_file ⇒ Object
- #create_model_files ⇒ Object
- #create_page_and_editable_fields_migration ⇒ Object
- #migration_version ⇒ Object
- #rails5_and_up? ⇒ Boolean
Instance Method Details
#add_editable_routes ⇒ Object
25 26 27 28 |
# File 'lib/editables/generators/editables/install_generator.rb', line 25 def add_editable_routes editable_route = "namespace :editables do\n\tresources :fields, only: [:update]\nend\n" route editable_route end |
#create_config_file ⇒ Object
12 13 14 15 16 |
# File 'lib/editables/generators/editables/install_generator.rb', line 12 def create_config_file config_dir_path = "config/editable" Dir.mkdir(config_dir_path) unless File.exist?(config_dir_path) template "config.yml", "#{config_dir_path}/config.yml" end |
#create_model_files ⇒ Object
18 19 20 21 22 23 |
# File 'lib/editables/generators/editables/install_generator.rb', line 18 def create_model_files model_dir_path = "app/models/editables" Dir.mkdir(model_dir_path) unless File.exist?(model_dir_path) template "field.rb", "#{model_dir_path}/field.rb" template "page.rb", "#{model_dir_path}/page.rb" end |
#create_page_and_editable_fields_migration ⇒ Object
8 9 10 |
# File 'lib/editables/generators/editables/install_generator.rb', line 8 def create_page_and_editable_fields_migration migration_template "migration.rb", "db/migrate/create_pages_and_fields.rb" end |
#migration_version ⇒ Object
34 35 36 37 38 |
# File 'lib/editables/generators/editables/install_generator.rb', line 34 def migration_version if rails5_and_up? "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" end end |
#rails5_and_up? ⇒ Boolean
30 31 32 |
# File 'lib/editables/generators/editables/install_generator.rb', line 30 def rails5_and_up? Rails::VERSION::MAJOR >= 5 end |