Class: Comable::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/comable/install/install_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_pathsObject


14
15
16
17
18
# File 'lib/generators/comable/install/install_generator.rb', line 14

def source_paths
  paths = superclass.source_paths
  paths << File.expand_path('../templates', __FILE__)
  paths.flatten
end

Instance Method Details

#add_filesObject


27
28
29
# File 'lib/generators/comable/install/install_generator.rb', line 27

def add_files
  template 'config/initializers/comable.rb', 'config/initializers/comable.rb'
end

#append_seedsObject


43
44
45
46
47
48
# File 'lib/generators/comable/install/install_generator.rb', line 43

def append_seeds
  append_file 'db/seeds.rb', <<-SEEDS
# Seed data for Comable
Comable::Core::Engine.load_seed if defined?(Comable::Core)
  SEEDS
end

#completeObject


102
103
104
# File 'lib/generators/comable/install/install_generator.rb', line 102

def complete
  message_for_complete unless options[:quiet]
end

#configure_applicationObject


31
32
33
34
35
36
37
38
39
40
41
# File 'lib/generators/comable/install/install_generator.rb', line 31

def configure_application
  application <<-APP
config.to_prepare do
  # Overriding Models and Controllers
  # refs: http://edgeguides.rubyonrails.org/engines.html#overriding-models-and-controllers
  Dir.glob(Rails.root.join('app/**/*_decorator*.rb')).each do |c|
    Rails.configuration.cache_classes ? require_dependency(c) : load(c)
  end
end
  APP
end

#create_databaseObject


55
56
57
58
# File 'lib/generators/comable/install/install_generator.rb', line 55

def create_database
  say_status :creating, 'database'
  quietly { rake 'db:create' }
end

#insert_routesObject


87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/generators/comable/install/install_generator.rb', line 87

def insert_routes
  insert_into_file File.join('config', 'routes.rb'), after: "Rails.application.routes.draw do\n" do
    <<-ROUTES
  # This line mounts Comable's routes at the root of your application.
  # This means, any requests to URLs such as /products, will go to Comable::ProductsController.
  # If you would like to change where this engine is mounted, simply change the :at option to something different.
  #
  # We ask that you don't use the :as option here, as Comable relies on it being the default of "comable"
  mount Comable::Core::Engine, at: '/'
    ROUTES
  end

  message_for_insert_routes unless options[:quiet]
end

#install_migrationsObject


50
51
52
53
# File 'lib/generators/comable/install/install_generator.rb', line 50

def install_migrations
  say_status :copying, 'migrations'
  quietly { rake 'comable:install:migrations' }
end

#load_sample_dataObject


78
79
80
81
82
83
84
85
# File 'lib/generators/comable/install/install_generator.rb', line 78

def load_sample_data
  if @sample_flag
    say_status :loading, 'sample data'
    quietly { rake 'comable:sample' }
  else
    say_status :skipping, 'sample data (you can always run rake comable:sample)'
  end
end

#load_seed_dataObject


69
70
71
72
73
74
75
76
# File 'lib/generators/comable/install/install_generator.rb', line 69

def load_seed_data
  if @seed_flag
    say_status :loading, 'seed data'
    rake_seed
  else
    say_status :skipping, 'seed data (you can always run rake db:seed)'
  end
end

#prepare_optionsObject


21
22
23
24
25
# File 'lib/generators/comable/install/install_generator.rb', line 21

def prepare_options
  @migrate_flag = options[:migrate]
  @seed_flag = @migrate_flag ? options[:seed] : false
  @sample_flag = @migrate_flag ? options[:sample] : false
end

#run_migrationsObject


60
61
62
63
64
65
66
67
# File 'lib/generators/comable/install/install_generator.rb', line 60

def run_migrations
  if @migrate_flag
    say_status :running, 'migrations'
    quietly { rake 'db:migrate' }
  else
    say_status :skipping, "migrations (don't forget to run rake db:migrate)"
  end
end