Class: YSI::Plugin
- Inherits:
-
Object
- Object
- YSI::Plugin
- Defined in:
- lib/yes_ship_it/plugin.rb
Instance Attribute Summary collapse
-
#err ⇒ Object
Returns the value of attribute err.
-
#out ⇒ Object
Returns the value of attribute out.
Instance Method Summary collapse
- #generate(name, display_name) ⇒ Object
-
#initialize(path) ⇒ Plugin
constructor
A new instance of Plugin.
- #list ⇒ Object
- #load ⇒ Object
Constructor Details
#initialize(path) ⇒ Plugin
Returns a new instance of Plugin.
5 6 7 8 9 10 |
# File 'lib/yes_ship_it/plugin.rb', line 5 def initialize(path) @plugin_dir = File.join(path, "yes_ship_it", "assertions") @out = STDOUT @err = STDERR end |
Instance Attribute Details
#err ⇒ Object
Returns the value of attribute err.
3 4 5 |
# File 'lib/yes_ship_it/plugin.rb', line 3 def err @err end |
#out ⇒ Object
Returns the value of attribute out.
3 4 5 |
# File 'lib/yes_ship_it/plugin.rb', line 3 def out @out end |
Instance Method Details
#generate(name, display_name) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/yes_ship_it/plugin.rb', line 46 def generate(name, display_name) plugin_path = File.join(@plugin_dir, name + ".rb") if File.exist?(plugin_path) err.puts "Can't generate plugin. Plugin already exists at `#{plugin_path}`." exit 1 end FileUtils.mkdir_p(@plugin_dir) File.open(plugin_path, "w") do |f| f.puts "module YSI" f.puts " class #{YSI::Assertion.class_name(name)} < Assertion" f.puts " def self.display_name" f.puts " \"#{display_name}\"" f.puts " end" f.puts f.puts " def check" f.puts " end" f.puts f.puts " def assert(executor)" f.puts " \"help me to do it\"" f.puts " end" f.puts " end" f.puts "end" end out.puts "Generated assertion plugin at `#{plugin_path}`." end |
#list ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/yes_ship_it/plugin.rb', line 28 def list plugins = load if plugins.empty? out.puts "There are no local plugins." out.puts out.puts "Create one with `yes_ship_it plugin init MyAssertion`." out.puts out.puts "Documentation about how to write plugins can be found at" out.puts out.puts " https://github.com/cornelius/yes_ship_it/wiki/plugins" else plugins.each do |plugin_name, plugin_class| out.puts "#{plugin_name}: #{plugin_class.display_name}" end end end |
#load ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/yes_ship_it/plugin.rb', line 12 def load plugin_paths = [] if File.exist?(@plugin_dir) plugin_paths = Dir.glob("#{@plugin_dir}/*.rb").sort end plugins = {} plugin_paths.each do |plugin_path| plugin_name = File.basename(plugin_path, ".rb") require plugin_path plugins[plugin_name] = YSI::Assertion.class_for_name(plugin_name) end plugins end |