Class: Telegrator::Generators::Bot

Inherits:
Base
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/telegrator/generators/bot/generator.rb

Constant Summary collapse

DATABASES =
%w[postgresql mongodb].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

dispatch

Constructor Details

#initialize(args = [], options = {}, config = {}) ⇒ Bot

Returns a new instance of Bot.



13
14
15
16
# File 'lib/telegrator/generators/bot/generator.rb', line 13

def initialize(args = [], options = {}, config = {})
  config[:destination_root] ||= args.first
  super
end

Class Method Details

.source_rootObject

TODO: move to Base class



9
10
11
# File 'lib/telegrator/generators/bot/generator.rb', line 9

def self.source_root
  File.expand_path('../templates', __FILE__)
end

Instance Method Details

#create_app_dirObject

app/ directory ===



51
52
53
# File 'lib/telegrator/generators/bot/generator.rb', line 51

def create_app_dir
  empty_directory 'app'
end

#create_bin_dirObject

bin/ directory ===



79
80
81
# File 'lib/telegrator/generators/bot/generator.rb', line 79

def create_bin_dir
  directory 'bin', mode: :preserve
end

#create_commandsObject



55
56
57
58
# File 'lib/telegrator/generators/bot/generator.rb', line 55

def create_commands
  template 'app/commands.rb'
  directory 'app/commands'
end

#create_config_dirObject

config/ directory ===



84
85
86
87
88
89
90
91
92
# File 'lib/telegrator/generators/bot/generator.rb', line 84

def create_config_dir
  directory 'config'

  if options[:skip_capistrano]
    remove_file 'config/deploy/'
    remove_file 'config/deploy.rb'
  end
  remove_file 'config/initializers/sequel.rb' if mongodb?
end

#create_db_dirObject

db/ directory ===



95
96
97
98
# File 'lib/telegrator/generators/bot/generator.rb', line 95

def create_db_dir
  return if mongodb?
  directory 'db'
end

#create_keyboardsObject

TODO: inline keyboards



62
63
64
65
66
# File 'lib/telegrator/generators/bot/generator.rb', line 62

def create_keyboards
  return if options[:skip_keyboards]
  template 'app/keyboards.rb'
  directory 'app/keyboards'
end

#create_lib_dirObject

lib/ directory ===



101
102
103
104
# File 'lib/telegrator/generators/bot/generator.rb', line 101

def create_lib_dir
  directory 'lib'
  remove_file 'lib/tasks/db.rake' if mongodb?
end

#create_log_dirObject

log/ directory ===



107
108
109
110
# File 'lib/telegrator/generators/bot/generator.rb', line 107

def create_log_dir
  empty_directory 'log'
  create_file 'log/.keep'
end

#create_modelsObject



68
69
70
71
# File 'lib/telegrator/generators/bot/generator.rb', line 68

def create_models
  template 'app/models.rb'
  directory 'app/models'
end

#create_root_filesObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/telegrator/generators/bot/generator.rb', line 38

def create_root_files
  template 'gitignore.tt', '.gitignore'
  inside { run 'git init' }

  template 'env.tt', '.env.sample'
  template 'env.tt', '.env'

  template 'Gemfile.tt'
  template 'Rakefile.tt'
  template 'Capfile.tt' unless options[:skip_capistrano]
end

#create_workersObject



73
74
75
76
# File 'lib/telegrator/generators/bot/generator.rb', line 73

def create_workers
  template 'app/workers.rb'
  directory 'app/workers'
end