Module: Better
- Defined in:
- lib/what_cd/better.rb
Class Method Summary collapse
-
.run(path, quality, verbose = false) ⇒ Object
Load from config file.
- .run_plugins(path, configured_plugins, quality) ⇒ Object
- .setup_log(verbose) ⇒ Object
Class Method Details
.run(path, quality, verbose = false) ⇒ Object
Load from config file
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/what_cd/better.rb', line 28 def self.run(path, quality, verbose=false) setup_log(verbose) # Load configured plugins begin # Get config config = YAML.load_file(WhatCD::CONFIG) # Get configured plugins configured_plugins = config['commands']['better']['plugins'] if configured_plugins # Run them self.run_plugins(path, configured_plugins, quality) else @log.info "No plugins to run. Edit your config to enable plugins." end rescue Errno::ENOENT @log.error "Missing gem config file '~/.what_cd'" end end |
.run_plugins(path, configured_plugins, quality) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/what_cd/better.rb', line 49 def self.run_plugins(path, configured_plugins, quality) # Get this directory current_dir = File.dirname(__FILE__) # Set the context to be passed around between plugins context = {} context[:path] = path context[:quality] = quality # Iterate over the configured plugins and dynamically execute them configured_plugins.each do |configured_plugin| file = "#{current_dir}/better_plugins/#{configured_plugin}.rb" require file file_name = File.basename(file, '.rb') # using ActiveSupport for camelcase and constantize plugin = file_name.camelcase.constantize # Check to ensure ruby file defines a class if plugin.class == Class @log.info "Bettering with plugin #{plugin}" context = plugin.new.better(context) @log.debug "context returned as #{context}" end end end |
.setup_log(verbose) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/what_cd/better.rb', line 19 def self. setup_log(verbose) if verbose @log.level = :debug else @log.level = :info end end |