Class: Bard::Target
- Inherits:
-
Object
- Object
- Bard::Target
- Defined in:
- lib/bard/target.rb,
lib/bard/plugins/deploy.rb,
lib/bard/plugins/github_pages.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?)
- #deploy_strategy ⇒ Object
- #deploy_strategy_instance ⇒ Object
-
#enable_capability(capability) ⇒ Object
Capability tracking.
- #exec!(command, home: false) ⇒ Object
- #github_pages(url = nil) ⇒ Object
- #has_capability?(capability) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(key, config) ⇒ Target
constructor
A new instance of Target.
- #path ⇒ Object
- #ping(*urls) ⇒ Object
- #ping! ⇒ Object
- #require_capability!(capability) ⇒ Object
- #run(command, home: false, verbose: false, quiet: false) ⇒ Object
- #run!(command, home: false, verbose: false, quiet: false, capture: false) ⇒ Object
- #ssh(uri = nil, **options) ⇒ Object
- #strategy_options(strategy_name) ⇒ 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.
7 8 9 10 11 12 |
# File 'lib/bard/target.rb', line 7 def initialize(key, config) @key = key @config = config @capabilities = [] @path = nil end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/bard/target.rb', line 5 def config @config end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
5 6 7 |
# File 'lib/bard/target.rb', line 5 def key @key end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
63 64 65 66 |
# File 'lib/bard/target.rb', line 63 def ==(other) return false unless other.is_a?(Bard::Target) comparable_state == other.comparable_state end |
#deploy_strategy ⇒ Object
221 222 223 |
# File 'lib/bard/plugins/deploy.rb', line 221 def deploy_strategy @deploy_strategy end |
#deploy_strategy_instance ⇒ Object
225 226 227 228 229 230 231 232 233 234 |
# File 'lib/bard/plugins/deploy.rb', line 225 def deploy_strategy_instance strategy = @deploy_strategy strategy ||= :ssh if has_capability?(:ssh) raise "No deployment strategy configured for target #{key}" unless strategy strategy_class = Bard::DeployStrategy[strategy] raise "Unknown deployment strategy: #{strategy}" unless strategy_class strategy_class.new(self) end |
#enable_capability(capability) ⇒ Object
Capability tracking
15 16 17 |
# File 'lib/bard/target.rb', line 15 def enable_capability(capability) @capabilities << capability unless @capabilities.include?(capability) end |
#exec!(command, home: false) ⇒ Object
42 43 44 |
# File 'lib/bard/target.rb', line 42 def exec!(command, home: false) Command.exec!(command) end |
#github_pages(url = nil) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/bard/plugins/github_pages.rb', line 21 def github_pages(url = nil) if url.nil? @github_pages_url else @deploy_strategy = :github_pages @github_pages_url = url enable_capability(:github_pages) end end |
#has_capability?(capability) ⇒ Boolean
19 20 21 |
# File 'lib/bard/target.rb', line 19 def has_capability?(capability) @capabilities.include?(capability) end |
#hash ⇒ Object
69 70 71 |
# File 'lib/bard/target.rb', line 69 def hash comparable_state.hash end |
#path ⇒ Object
29 30 31 |
# File 'lib/bard/target.rb', line 29 def path @path || config.project_name end |
#ping(*urls) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/bard/plugins/ping/target_methods.rb', line 6 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 |
#ping! ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/bard/plugins/ping/target_methods.rb', line 16 def ping! require_capability!(:url) failed_urls = Bard::Ping.call(self) if failed_urls.any? raise "Ping failed for: #{failed_urls.join(", ")}" end end |
#require_capability!(capability) ⇒ Object
23 24 25 26 27 |
# File 'lib/bard/target.rb', line 23 def require_capability!(capability) unless has_capability?(capability) raise "#{capability} capability not configured for this target" end end |
#run(command, home: false, verbose: false, quiet: false) ⇒ Object
38 39 40 |
# File 'lib/bard/target.rb', line 38 def run(command, home: false, verbose: false, quiet: false) Command.run(command, verbose:, quiet:) end |
#run!(command, home: false, verbose: false, quiet: false, capture: false) ⇒ Object
33 34 35 36 |
# File 'lib/bard/target.rb', line 33 def run!(command, home: false, verbose: false, quiet: false, capture: false) result = Command.run!(command, verbose:, quiet:) result if capture 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 |
#strategy_options(strategy_name) ⇒ Object
236 237 238 239 |
# File 'lib/bard/plugins/deploy.rb', line 236 def (strategy_name) @strategy_options_hash ||= {} @strategy_options_hash[strategy_name] || {} end |
#to_s ⇒ Object
Utility methods
47 48 49 |
# File 'lib/bard/target.rb', line 47 def to_s key.to_s end |
#to_sym ⇒ Object
51 52 53 |
# File 'lib/bard/target.rb', line 51 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
55 56 57 58 59 60 61 |
# File 'lib/bard/target.rb', line 55 def with(attrs) dup.tap do |t| attrs.each do |key, value| t.send(key, value) end end end |