Class: Bard::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/bard/config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_name, path: nil, source: nil) ⇒ Config

Returns a new instance of Config.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/bard/config.rb', line 11

def initialize project_name, path: nil, source: nil
  @project_name = project_name
  @servers = {
    local: Server.new(
      project_name,
      :local,
      false,
      "./",
      ["#{project_name}.local"],
    ),
    gubs: Server.new(
      project_name,
      :gubs,
      "[email protected]:22022",
      "Sites/#{project_name}",
      false,
    ),
    ci: Server.new(
      project_name,
      :ci,
      "[email protected]:22022",
      "jobs/#{project_name}/workspace",
      false,
    ),
    staging: Server.new(
      project_name,
      :staging,
      "[email protected]:22022",
      project_name,
      ["#{project_name}.botandrose.com"],
    ),
  }
  if path && File.exist?(path)
    source = File.read(path)
  end
  if source
    instance_eval source
  end
end

Instance Attribute Details

#project_nameObject (readonly)

Returns the value of attribute project_name.



51
52
53
# File 'lib/bard/config.rb', line 51

def project_name
  @project_name
end

#serversObject (readonly)

Returns the value of attribute servers.



51
52
53
# File 'lib/bard/config.rb', line 51

def servers
  @servers
end

Class Method Details

.current(working_directory: Dir.getwd) ⇒ Object



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

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



58
59
60
61
62
63
64
# File 'lib/bard/config.rb', line 58

def [] key
  key = key.to_sym
  if @servers[key].nil? && key == :production
    key = :staging
  end
  @servers[key]
end

#backup(value = nil, &block) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/bard/config.rb', line 74

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 { bard }
  else
    raise ArgumentError, "backup accepts false or a block"
  end
end

#data(*paths) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/bard/config.rb', line 66

def data *paths
  if paths.length == 0
    Array(@data)
  else
    @data = paths
  end
end

#github_pages(url) ⇒ Object

short-hand for michael



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/bard/config.rb', line 88

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

  server :production do
    github_pages true
    ssh false
    ping *urls
  end

  backup false
end

#server(key, &block) ⇒ Object



53
54
55
56
# File 'lib/bard/config.rb', line 53

def server key, &block
  key = key.to_sym
  @servers[key] = Server.define(project_name, key, &block)
end