Class: Cinch::BotTemplate::Classes::Bot
- Inherits:
-
Object
- Object
- Cinch::BotTemplate::Classes::Bot
- Defined in:
- lib/cinch/bot_template/classes/bot.rb
Instance Method Summary collapse
- #generate(directory:, config_file:) ⇒ Object
- #get_001_bot_file ⇒ Object
- #get_002_config_file ⇒ Object
-
#initialize(options:, shell:, all: false) ⇒ Bot
constructor
A new instance of Bot.
Constructor Details
#initialize(options:, shell:, all: false) ⇒ Bot
Returns a new instance of Bot.
9 10 11 12 13 14 15 16 |
# File 'lib/cinch/bot_template/classes/bot.rb', line 9 def initialize(options:, shell:, all: false) @hl = HighLine.new($stdin, $stderr, 80) @opts = Hash.new { |hash, key| hash[key] = {} } = @all = all @shell = shell end |
Instance Method Details
#generate(directory:, config_file:) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/cinch/bot_template/classes/bot.rb', line 41 def generate(directory:, config_file:) @directory = directory @config_file = config_file if .fetch(:debug, nil) at_exit do puts puts @opts end end meths = self.methods.select { |x| x =~ /^get_[0-9]+_.*/ } meths.sort! { |m, n| m.to_s.gsub(/^get_([0-9]+)_.*/, '\1').to_i <=> n.to_s.gsub(/^get_([0-9]+)_.*/, '\1').to_i } meths.each do |m| self.send(m) end @hl.say "Generating..." tpl = Cinch::BotTemplate::Templates::Bot.new.generate( multi: ['multi-server'], config_file: @config_file, ) if @opts.fetch('stdout', nil) puts tpl else filename = Pathname(directory).join(@opts.dig('bot', 'file')) open filename, 'a+' do |fd| fd.puts tpl end File.chmod(775, filename) end end |
#get_001_bot_file ⇒ Object
Note:
What the executable file will be named + .rb
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cinch/bot_template/classes/bot.rb', line 19 def get_001_bot_file @hl.say "What should the executable file be named." unless @all @hl.say "Use a hyphen by itself '-' to output to stdout " @hl.say "instead of a file." end @hl.say "The generator will add .rb automatically." filename = @hl.ask " > ", String if filename == '-' @opts['stdout'] = true return end @opts['bot']['file'] = filename.include?('.rb') ? filename : filename + '.rb' end |
#get_002_config_file ⇒ Object
34 35 36 37 |
# File 'lib/cinch/bot_template/classes/bot.rb', line 34 def get_002_config_file @shell.say "Grabbing config path from state..." @opts['config_path'] = Pathname(@directory).join(@config_file) end |