Class: Bard::Config

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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_nameObject (readonly)

Returns the value of attribute project_name.



21
22
23
# File 'lib/bard/config.rb', line 21

def project_name
  @project_name
end

#targetsObject (readonly)

Returns the value of attribute targets.



21
22
23
# File 'lib/bard/config.rb', line 21

def targets
  @targets
end

Class Method Details

.currentObject



7
8
9
# File 'lib/bard/config.rb', line 7

def self.current
  new(detect_project_name, path: "bard.rb")
end

.detect_project_nameObject



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.expand_path(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

#target(key, &block) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/bard/config.rb', line 40

def target(key, &block)
  key = key.to_sym
  unless @targets[key].is_a?(Target)
    @targets[key] = Target.new(key, self)
  end
  @targets[key].instance_eval(&block) if block
  @targets[key]
end