Class: Bard::Server

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#envObject

Returns the value of attribute env

Returns:

  • (Object)

    the current value of env



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

def env
  @env
end

#gatewayObject

Returns the value of attribute gateway

Returns:

  • (Object)

    the current value of gateway



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

def gateway
  @gateway
end

#github_pagesObject

Returns the value of attribute github_pages

Returns:

  • (Object)

    the current value of github_pages



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

def github_pages
  @github_pages
end

#keyObject

Returns the value of attribute key

Returns:

  • (Object)

    the current value of key



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

def key
  @key
end

#path(*args) ⇒ Object

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



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

def path
  @path
end

#ping(*args) ⇒ Object

Returns the value of attribute ping

Returns:

  • (Object)

    the current value of ping



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

def ping
  @ping
end

#project_nameObject

Returns the value of attribute project_name

Returns:

  • (Object)

    the current value of project_name



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

def project_name
  @project_name
end

#sshObject

Returns the value of attribute ssh

Returns:

  • (Object)

    the current value of ssh



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

def ssh
  @ssh
end

#ssh_keyObject

Returns the value of attribute ssh_key

Returns:

  • (Object)

    the current value of ssh_key



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

def ssh_key
  @ssh_key
end

Class Method Details

.define(project_name, key, &block) ⇒ Object



8
9
10
11
12
# File 'lib/bard/server.rb', line 8

def self.define project_name, key, &block
  new(project_name, key).tap do |server|
    server.instance_eval &block
  end
end

.setting(*fields) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/bard/server.rb', line 14

def self.setting *fields
  fields.each do |field|
    define_method field do |*args|
      if args.length == 1
        send :"#{field}=", args.first
      elsif args.length == 0
        super()
      else
        raise ArgumentError
      end
    end
  end
end

.setting_with_deprecation(*fields, message:) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/bard/server.rb', line 28

def self.setting_with_deprecation *fields, message:
  fields.each do |field|
    define_method field do |*args|
      if args.length == 1
        Deprecation.warn message
        send :"#{field}=", args.first
      elsif args.length == 0
        super()
      else
        raise ArgumentError
      end
    end
  end
end

Instance Method Details

#copy_dir(path, to:, verbose: false) ⇒ Object



154
155
156
# File 'lib/bard/server.rb', line 154

def copy_dir path, to:, verbose: false
  Bard::Copy.dir path, from: self, to:, verbose:
end

#copy_file(path, to:, verbose: false) ⇒ Object



150
151
152
# File 'lib/bard/server.rb', line 150

def copy_file path, to:, verbose: false
  Bard::Copy.file path, from: self, to:, verbose:
end

#exec!(command, home: false) ⇒ Object



146
147
148
# File 'lib/bard/server.rb', line 146

def exec! command, home: false
  Bard::Command.exec! command, on: self, home:
end

#option(key, value) ⇒ Object



85
86
87
88
89
# File 'lib/bard/server.rb', line 85

def option(key, value)
  Deprecation.warn "`option` is deprecated; pass options as keyword arguments to the strategy method, e.g., `jets \"url\", run_tests: true` (will be removed in v2.0)"
  @options ||= {}
  @options[key] = value
end

#portObject



104
105
106
# File 'lib/bard/server.rb', line 104

def port
  ssh_uri.port || 22
end

#rsync_uri(file_path = nil) ⇒ Object



116
117
118
119
120
121
122
123
124
# File 'lib/bard/server.rb', line 116

def rsync_uri file_path=nil
  str = ssh_uri.dup.tap do |uri|
    uri.send :set_scheme, nil
    uri.send :set_port, nil
  end.to_s[2..]
  str += ":#{path}"
  str += "/#{file_path}" if file_path
  str
end

#run(command, home: false, verbose: false, quiet: false) ⇒ Object



142
143
144
# File 'lib/bard/server.rb', line 142

def run command, home: false, verbose: false, quiet: false
  Bard::Command.run command, on: self, home:, verbose:, quiet:
end

#run!(command, home: false, verbose: false, quiet: false) ⇒ Object



138
139
140
# File 'lib/bard/server.rb', line 138

def run! command, home: false, verbose: false, quiet: false
  Bard::Command.run! command, on: self, home:, verbose:, quiet:
end

#scp_uri(file_path = nil) ⇒ Object



108
109
110
111
112
113
114
# File 'lib/bard/server.rb', line 108

def scp_uri file_path=nil
  ssh_uri.dup.tap do |uri|
    uri.scheme = "scp"
    uri.path = "/#{path}"
    uri.path += "/#{file_path}" if file_path
  end
end

#ssh_uri(which = :ssh) ⇒ Object



99
100
101
102
# File 'lib/bard/server.rb', line 99

def ssh_uri which=:ssh
  value = send(which)
  URI("ssh://#{value}")
end

#strategy(name) ⇒ Object



80
81
82
83
# File 'lib/bard/server.rb', line 80

def strategy(name)
  Deprecation.warn "`strategy` is deprecated; use the strategy method directly, e.g., `jets \"url\"` instead of `strategy :jets` (will be removed in v2.0)"
  @strategy = name
end

#strategy_nameObject



91
92
93
# File 'lib/bard/server.rb', line 91

def strategy_name
  @strategy
end

#strategy_optionsObject



95
96
97
# File 'lib/bard/server.rb', line 95

def strategy_options
  @options || {}
end

#to_symObject



134
135
136
# File 'lib/bard/server.rb', line 134

def to_sym
  key
end

#with(attrs) ⇒ Object



126
127
128
129
130
131
132
# File 'lib/bard/server.rb', line 126

def with(attrs)
  dup.tap do |s|
    attrs.each do |key, value|
      s.send key, value
    end
  end
end