Class: Bard::Target
- Inherits:
-
Object
- Object
- Bard::Target
- Defined in:
- lib/bard/target.rb,
lib/bard/plugins/ssh/target_methods.rb,
lib/bard/plugins/url/target_methods.rb,
lib/bard/plugins/ping/target_methods.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#enable_capability(capability) ⇒ Object
Capability tracking.
- #has_capability?(capability) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(key, config) ⇒ Target
constructor
A new instance of Target.
- #path ⇒ Object
- #ping(*urls) ⇒ Object
- #require_capability!(capability) ⇒ Object
- #ssh(uri = nil, **options) ⇒ Object
-
#to_s ⇒ Object
Utility methods.
- #to_sym ⇒ Object
- #url(value = nil) ⇒ Object
- #with(attrs) ⇒ Object
Constructor Details
#initialize(key, config) ⇒ Target
Returns a new instance of Target.
5 6 7 8 9 10 |
# File 'lib/bard/target.rb', line 5 def initialize(key, config) @key = key @config = config @capabilities = [] @path = nil end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
3 4 5 |
# File 'lib/bard/target.rb', line 3 def config @config end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
3 4 5 |
# File 'lib/bard/target.rb', line 3 def key @key end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
48 49 50 51 |
# File 'lib/bard/target.rb', line 48 def ==(other) return false unless other.is_a?(Bard::Target) comparable_state == other.comparable_state end |
#enable_capability(capability) ⇒ Object
Capability tracking
13 14 15 |
# File 'lib/bard/target.rb', line 13 def enable_capability(capability) @capabilities << capability unless @capabilities.include?(capability) end |
#has_capability?(capability) ⇒ Boolean
17 18 19 |
# File 'lib/bard/target.rb', line 17 def has_capability?(capability) @capabilities.include?(capability) end |
#hash ⇒ Object
54 55 56 |
# File 'lib/bard/target.rb', line 54 def hash comparable_state.hash end |
#path ⇒ Object
27 28 29 |
# File 'lib/bard/target.rb', line 27 def path @path || config.project_name end |
#ping(*urls) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/bard/plugins/ping/target_methods.rb', line 5 def ping(*urls) if urls.empty? @ping_urls || [url].compact elsif urls.first == false @ping_urls = [] else @ping_urls = urls.flatten.map { |u| normalize_url(u) } end end |
#require_capability!(capability) ⇒ Object
21 22 23 24 25 |
# File 'lib/bard/target.rb', line 21 def require_capability!(capability) unless has_capability?(capability) raise "#{capability} capability not configured for this target" end end |
#ssh(uri = nil, **options) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/bard/plugins/ssh/target_methods.rb', line 6 def ssh(uri = nil, **) if uri.nil? return @server else extend Bard::SSH @server = Bard::SSHServer.new(uri, **) @path = [:path] if [:path] enable_capability(:ssh) hostname = @server.hostname url("https://#{hostname}") if hostname end end |
#to_s ⇒ Object
Utility methods
32 33 34 |
# File 'lib/bard/target.rb', line 32 def to_s key.to_s end |
#to_sym ⇒ Object
36 37 38 |
# File 'lib/bard/target.rb', line 36 def to_sym key end |
#url(value = nil) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/bard/plugins/url/target_methods.rb', line 4 def url(value = nil) if value.nil? @url elsif value == false @url = nil @capabilities.delete(:url) else @url = normalize_url(value) enable_capability(:url) end end |
#with(attrs) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/bard/target.rb', line 40 def with(attrs) dup.tap do |t| attrs.each do |key, value| t.send(key, value) end end end |