Class: Cinch::BotTemplate::Classes::Plugin
- Inherits:
-
Object
- Object
- Cinch::BotTemplate::Classes::Plugin
- Defined in:
- lib/cinch/bot_template/classes/plugin.rb
Instance Method Summary collapse
- #generate(directory: Pathname('.').realdirpath.to_s) ⇒ Object
- #get_001_plugin_names ⇒ Object
-
#initialize(shell:, options:, all: false) ⇒ Plugin
constructor
A new instance of Plugin.
- #parse_config_path(file_path) ⇒ Object
Constructor Details
#initialize(shell:, options:, all: false) ⇒ Plugin
Returns a new instance of Plugin.
9 10 11 12 13 14 15 |
# File 'lib/cinch/bot_template/classes/plugin.rb', line 9 def initialize(shell:, options:, all: false) @hl = HighLine.new($stdin, $stderr, 80) @opts = Hash.new { |hash, key| hash[key] = {} } @all = all @shell = shell @options = end |
Instance Method Details
#generate(directory: Pathname('.').realdirpath.to_s) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cinch/bot_template/classes/plugin.rb', line 32 def generate(directory: Pathname('.').realdirpath.to_s) 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..." plugins = Cinch::BotTemplate::Templates::Plugin.generate(plugin_names: @opts['plugin_names']) FileUtils.mkpath(directory.join('plugins')) plugins.each do |plugin, text| open Pathname(directory).join('plugins', plugin), 'w' do |fd| fd.puts text end end end |
#get_001_plugin_names ⇒ Object
24 25 26 27 28 29 |
# File 'lib/cinch/bot_template/classes/plugin.rb', line 24 def get_001_plugin_names @hl.say "What's the plugin name(s)?" @hl.say "Each name you put here will have 'Plugin' appended to it." @hl.say "Each name will become a separate plugin file" @opts['plugin_names'] = @hl.ask " > ", -> (str) { str.split(' ') } end |
#parse_config_path(file_path) ⇒ Object
18 19 20 21 22 |
# File 'lib/cinch/bot_template/classes/plugin.rb', line 18 def parse_config_path(file_path) path = Pathname(file_path) path = File.(path) path.to_s end |