Class: Bard::Config
- Inherits:
-
Object
- Object
- Bard::Config
- Defined in:
- lib/bard/config.rb
Instance Attribute Summary collapse
-
#project_name ⇒ Object
readonly
Returns the value of attribute project_name.
-
#targets ⇒ Object
readonly
New v2.0 accessor (same as servers).
Class Method Summary collapse
Instance Method Summary collapse
-
#[](key) ⇒ Object
Get a server/target by key.
- #backup(value = nil, &block) ⇒ Object
- #backup_enabled? ⇒ Boolean
-
#ci(system = nil) ⇒ Object
CI configuration.
- #ci_instance(branch) ⇒ Object
- #ci_system ⇒ Object
-
#data(*paths) ⇒ Object
Data paths configuration.
- #data_paths ⇒ Object
- #github_pages(url) ⇒ Object
-
#initialize(project_name = nil, path: nil, source: nil) ⇒ Config
constructor
A new instance of Config.
-
#server(key, &block) ⇒ Object
Old v1.x API - creates Server instances.
-
#servers ⇒ Object
Backward compatible accessor.
-
#target(key, &block) ⇒ Object
New v2.0 API - creates Target instances.
Constructor Details
#initialize(project_name = nil, path: nil, source: nil) ⇒ Config
Returns a new instance of Config.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bard/config.rb', line 15 def initialize(project_name = nil, path: nil, source: nil) # Support both positional and keyword argument for project_name @project_name = project_name @servers = {} # Unified hash for both Server and Target instances @data_paths = [] @backup = nil @ci_system = nil # Load default configuration (creates Server instances for backward compat) load_defaults if project_name # Load user configuration if path && File.exist?(path) source = File.read(path) end if source instance_eval(source) end end |
Instance Attribute Details
#project_name ⇒ Object (readonly)
Returns the value of attribute project_name.
13 14 15 |
# File 'lib/bard/config.rb', line 13 def project_name @project_name end |
#targets ⇒ Object (readonly)
New v2.0 accessor (same as servers)
41 42 43 |
# File 'lib/bard/config.rb', line 41 def targets @targets end |
Class Method Details
.current(working_directory: Dir.getwd) ⇒ Object
7 8 9 10 11 |
# File 'lib/bard/config.rb', line 7 def self.current(working_directory: Dir.getwd) project_name = File.basename(working_directory) path = File.join(working_directory, "bard.rb") new(project_name, path: path) end |
Instance Method Details
#[](key) ⇒ Object
Get a server/target by key
61 62 63 64 65 66 67 68 |
# File 'lib/bard/config.rb', line 61 def [](key) key = key.to_sym # Fallback to staging if production not defined if @servers[key].nil? && key == :production key = :staging end @servers[key] end |
#backup(value = nil, &block) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/bard/config.rb', line 83 def backup(value = nil, &block) if block_given? @backup = BackupConfig.new(&block) elsif value == false @backup = BackupConfig.new { disabled } elsif value.nil? # Getter @backup ||= BackupConfig.new { } else raise ArgumentError, "backup accepts false or a block" end end |
#backup_enabled? ⇒ Boolean
95 96 97 |
# File 'lib/bard/config.rb', line 95 def backup_enabled? backup == true end |
#ci(system = nil) ⇒ Object
CI configuration
118 119 120 121 122 123 124 |
# File 'lib/bard/config.rb', line 118 def ci(system = nil) if system.nil? @ci_system else @ci_system = system end end |
#ci_instance(branch) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/bard/config.rb', line 130 def ci_instance(branch) return nil if @ci_system == false require "bard/ci" # Use the existing CI class which handles auto-detection case @ci_system when :local CI.new(project_name, branch, local: true) when :github_actions, :jenkins, nil # CI class auto-detects between github_actions and jenkins CI.new(project_name, branch) when false nil else CI.new(project_name, branch) end end |
#ci_system ⇒ Object
126 127 128 |
# File 'lib/bard/config.rb', line 126 def ci_system @ci_system end |
#data(*paths) ⇒ Object
Data paths configuration
71 72 73 74 75 76 77 |
# File 'lib/bard/config.rb', line 71 def data(*paths) if paths.empty? @data_paths else @data_paths = paths end end |
#data_paths ⇒ Object
79 80 81 |
# File 'lib/bard/config.rb', line 79 def data_paths @data_paths end |
#github_pages(url) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/bard/config.rb', line 99 def github_pages url urls = [] uri = url.start_with?("http") ? URI.parse(url) : URI.parse("https://#{url}") hostname = uri.hostname.sub(/^www\./, '') urls = [hostname] if hostname.count(".") < 2 urls << "www.#{hostname}" end target :production do github_pages url ssh false ping(*urls) if urls.any? end backup false end |
#server(key, &block) ⇒ Object
Old v1.x API - creates Server instances
46 47 48 49 50 |
# File 'lib/bard/config.rb', line 46 def server(key, &block) Deprecation.warn "`server` is deprecated; use `target` instead (will be removed in v2.0)" key = key.to_sym @servers[key] = Server.define(project_name, key, &block) end |
#servers ⇒ Object
Backward compatible accessor
36 37 38 |
# File 'lib/bard/config.rb', line 36 def servers @servers end |