Class: Bard::Config
- Inherits:
-
Object
- Object
- Bard::Config
- Defined in:
- lib/bard/config.rb,
lib/bard/plugins/data.rb,
lib/bard/plugins/deploy.rb,
lib/bard/plugins/github_pages.rb
Instance Attribute Summary collapse
-
#project_name ⇒ Object
readonly
Returns the value of attribute project_name.
-
#targets ⇒ Object
readonly
Returns the value of attribute targets.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #ci(system = nil) ⇒ Object
- #data(*paths) ⇒ Object
- #github_pages(url) ⇒ Object
-
#initialize(project_name = nil, path: nil, source: nil) ⇒ Config
constructor
A new instance of Config.
- #remove_target(key) ⇒ Object
- #target(key, &block) ⇒ Object
Constructor Details
#initialize(project_name = nil, path: nil, source: nil) ⇒ Config
Returns a new instance of Config.
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bard/config.rb', line 23 def initialize(project_name = nil, path: nil, source: nil) @project_name = project_name @targets = {} load_defaults if project_name if path && File.exist?(path) source = File.read(path) end if source instance_eval(source, path) end end |
Instance Attribute Details
#project_name ⇒ Object (readonly)
Returns the value of attribute project_name.
21 22 23 |
# File 'lib/bard/config.rb', line 21 def project_name @project_name end |
#targets ⇒ Object (readonly)
Returns the value of attribute targets.
21 22 23 |
# File 'lib/bard/config.rb', line 21 def targets @targets end |
Class Method Details
.current ⇒ Object
7 8 9 |
# File 'lib/bard/config.rb', line 7 def self.current new(detect_project_name, path: "bard.rb") end |
.detect_project_name ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/bard/config.rb', line 11 def self.detect_project_name git_common_dir = `git rev-parse --git-common-dir 2>/dev/null`.chomp dirname = if $?.success? && !git_common_dir.empty? File.dirname(File.(git_common_dir)) else Dir.getwd end File.basename(dirname) end |
Instance Method Details
#[](key) ⇒ Object
49 50 51 |
# File 'lib/bard/config.rb', line 49 def [](key) @targets[key.to_sym] end |
#ci(system = nil) ⇒ Object
209 210 211 212 213 214 215 |
# File 'lib/bard/plugins/deploy.rb', line 209 def ci(system = nil) if system.nil? @ci_system else @ci_system = system end end |
#data(*paths) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/bard/plugins/data.rb', line 49 def data(*paths) if paths.empty? @data_paths ||= [] else @data_paths = paths end end |
#github_pages(url) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/bard/plugins/github_pages.rb', line 6 def github_pages(url) uri = url.start_with?("http") ? URI.parse(url) : URI.parse("https://#{url}") hostname = uri.hostname.sub(/^www\./, "") remove_target :production target :production do github_pages url url(hostname) if hostname end backup(false) if respond_to?(:backup) end |
#remove_target(key) ⇒ Object
36 37 38 |
# File 'lib/bard/config.rb', line 36 def remove_target(key) @targets.delete(key.to_sym) end |