Class: Editables::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/editables/generators/editables/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_editable_routesObject



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_fileObject



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_filesObject



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_migrationObject



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_versionObject



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

Returns:

  • (Boolean)


30
31
32
# File 'lib/editables/generators/editables/install_generator.rb', line 30

def rails5_and_up?
  Rails::VERSION::MAJOR >= 5
end