Class: WatchmonkeyCli::Application::Configuration
- Inherits:
-
Object
- Object
- WatchmonkeyCli::Application::Configuration
- Defined in:
- lib/watchmonkey_cli/application/configuration.rb
Defined Under Namespace
Modules: AppHelper
Instance Method Summary collapse
-
#initialize(app, file = nil, tags = []) ⇒ Configuration
constructor
A new instance of Configuration.
- #method_missing(meth, *args, &block) ⇒ Object
- #ssh_connection(name, opts = {}, &b) ⇒ Object
- #tag_all!(*tags) ⇒ Object
Constructor Details
#initialize(app, file = nil, tags = []) ⇒ Configuration
Returns a new instance of Configuration.
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/watchmonkey_cli/application/configuration.rb', line 62 def initialize app, file = nil, = [] @app = app @file = file @tags = return unless file begin eval File.read(file, encoding: "utf-8"), binding, file rescue app.error "Invalid config file #{file}" raise end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/watchmonkey_cli/application/configuration.rb', line 83 def method_missing meth, *args, &block if c = @app.checkers[meth.to_s] opts = args. only = @app.opts[:tag_only] except = @app.opts[:tag_except] # build tags = (@tags + (opts[:tags] || []).map(&:to_sym)) if @app.opts[:autotag] << :"WMC-#{c.class.checker_name}" # checker name if args[0].is_a?(Symbol) << :"WMS-#{args[0]}" # ssh/local connection elsif args[0].is_a?(String) && args[0].match(/\Ahttp(s)?:\/\//i) uri = URI.parse(args[0]) rescue false << :"WMH-#{uri.hostname.gsub(".", "_")}" if uri # hostname from URL end end = .uniq @app.tag_list.merge() if only.any? if .any?{|t| only.include?(t) } if .any?{|t| except.include?(t) } return @app.debug "Skipping #{meth} with #{args} and #{opts} due to tag_except filter..." end else return @app.debug "Skipping #{meth} with #{args} and #{opts} due to tag_only filter..." end elsif .any?{|t| except.include?(t) } return @app.debug "Skipping #{meth} with #{args} and #{opts} due to tag_except filter..." end c.enqueue(*args, opts.merge(tags: )) else super end end |
Instance Method Details
#ssh_connection(name, opts = {}, &b) ⇒ Object
75 76 77 |
# File 'lib/watchmonkey_cli/application/configuration.rb', line 75 def ssh_connection name, opts = {}, &b @app.fetch_connection(:ssh, name, opts, &b) end |
#tag_all!(*tags) ⇒ Object
79 80 81 |
# File 'lib/watchmonkey_cli/application/configuration.rb', line 79 def tag_all! * @tags = .map(&:to_sym) end |