Class: Lit::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_lit_initializerObject



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_dependencyObject



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_cacheObject



63
64
65
# File 'lib/generators/lit/install_generator.rb', line 63

def clear_cache
  Lit.init.cache.reset
end

#copy_migrationsObject



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_keyObject



42
43
44
# File 'lib/generators/lit/install_generator.rb', line 42

def generate_api_key
  @api_key = SecureRandom.base64 32
end

#mount_engineObject



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_migrationsObject



56
57
58
59
60
61
# File 'lib/generators/lit/install_generator.rb', line 56

def run_migrations
  unless options['no-migrate']
    puts 'Running rake db:migrate'
    `rake db:migrate`
  end
end

#set_authentication_functionObject



20
21
22
23
24
# File 'lib/generators/lit/install_generator.rb', line 20

def set_authentication_function
  @authentication_function = options['authentication-function'].presence ||
        ask("What's the authentication function, ie. :authenticate_user! :").presence ||
        nil
end

#set_key_value_engineObject



26
27
28
29
30
# File 'lib/generators/lit/install_generator.rb', line 26

def set_key_value_engine
  @key_value_engine = options['key-value-engine'].presence ||
        ask("What's the key value engine? ([hash] OR redis):").presence ||
        :hash
end