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
63 64 65 66 67 68 69 70 |
# File 'lib/bard/config.rb', line 63 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
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/bard/config.rb', line 85 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
97 98 99 |
# File 'lib/bard/config.rb', line 97 def backup_enabled? backup == true end |
#ci(system = nil) ⇒ Object
CI configuration
120 121 122 123 124 125 126 |
# File 'lib/bard/config.rb', line 120 def ci(system = nil) if system.nil? @ci_system else @ci_system = system end end |
#ci_instance(branch) ⇒ Object
132 133 134 135 136 137 |
# File 'lib/bard/config.rb', line 132 def ci_instance(branch) return nil if @ci_system == false require "bard/ci" CI.new(project_name, branch, runner_name: @ci_system) end |
#ci_system ⇒ Object
128 129 130 |
# File 'lib/bard/config.rb', line 128 def ci_system @ci_system end |
#data(*paths) ⇒ Object
Data paths configuration
73 74 75 76 77 78 79 |
# File 'lib/bard/config.rb', line 73 def data(*paths) if paths.empty? @data_paths else @data_paths = paths end end |
#data_paths ⇒ Object
81 82 83 |
# File 'lib/bard/config.rb', line 81 def data_paths @data_paths end |
#github_pages(url) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/bard/config.rb', line 101 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 |
#target(key, &block) ⇒ Object
New v2.0 API - creates Target instances
53 54 55 56 57 58 59 60 |
# File 'lib/bard/config.rb', line 53 def target(key, &block) key = key.to_sym unless @servers[key].is_a?(Target) @servers[key] = Target.new(key, self) end @servers[key].instance_eval(&block) if block @servers[key] end |