Class: Lit::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Lit::Generators::InstallGenerator
- Defined in:
- lib/generators/lit/install_generator.rb
Instance Method Summary collapse
- #add_lit_initializer ⇒ Object
- #add_redis_dependency ⇒ Object
- #clear_cache ⇒ Object
- #copy_migrations ⇒ Object
- #generate_api_key ⇒ Object
- #mount_engine ⇒ Object
- #run_migrations ⇒ Object
- #set_authentication_function ⇒ Object
- #set_key_value_engine ⇒ Object
Instance Method Details
#add_lit_initializer ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/generators/lit/install_generator.rb', line 46 def add_lit_initializer path = "#{::Rails.root}/config/initializers/lit.rb" if File.exist?(path) puts 'Skipping config/initializers/lit.rb creation, file already exists!' else puts 'Adding lit initializer (config/initializers/lit.rb)...' template 'initializer.rb', path end end |
#add_redis_dependency ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/generators/lit/install_generator.rb', line 32 def add_redis_dependency if @key_value_engine == 'redis' puts 'Adding redis dependency' gem 'redis' Bundler.with_clean_env do run 'bundle install' end end end |
#clear_cache ⇒ Object
63 64 65 |
# File 'lib/generators/lit/install_generator.rb', line 63 def clear_cache Lit.init.cache.reset end |
#copy_migrations ⇒ Object
13 14 15 16 17 18 |
# File 'lib/generators/lit/install_generator.rb', line 13 def copy_migrations puts 'Copying Lit migrations...' Dir.chdir(::Rails.root) do `rake lit:install:migrations` end end |
#generate_api_key ⇒ Object
42 43 44 |
# File 'lib/generators/lit/install_generator.rb', line 42 def generate_api_key @api_key = SecureRandom.base64 32 end |
#mount_engine ⇒ Object
67 68 69 70 |
# File 'lib/generators/lit/install_generator.rb', line 67 def mount_engine puts "Mounting Lit::Engine at \"/lit\" in config/routes.rb..." route "mount Lit::Engine => '/lit'" end |
#run_migrations ⇒ Object
56 57 58 59 60 61 |
# File 'lib/generators/lit/install_generator.rb', line 56 def run_migrations unless ['no-migrate'] puts 'Running rake db:migrate' `rake db:migrate` end end |
#set_authentication_function ⇒ Object
20 21 22 23 24 |
# File 'lib/generators/lit/install_generator.rb', line 20 def set_authentication_function @authentication_function = ['authentication-function'].presence || ask("What's the authentication function, ie. :authenticate_user! :").presence || nil end |
#set_key_value_engine ⇒ Object
26 27 28 29 30 |
# File 'lib/generators/lit/install_generator.rb', line 26 def set_key_value_engine @key_value_engine = ['key-value-engine'].presence || ask("What's the key value engine? ([hash] OR redis):").presence || :hash end |