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



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

def env
  @env
end

#gatewayObject

Returns the value of attribute gateway

Returns:

  • (Object)

    the current value of gateway



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

def gateway
  @gateway
end

#keyObject

Returns the value of attribute key

Returns:

  • (Object)

    the current value of key



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

def key
  @key
end

#path(*args) ⇒ Object

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



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

def path
  @path
end

#ping(*args) ⇒ Object

Returns the value of attribute ping

Returns:

  • (Object)

    the current value of ping



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

def ping
  @ping
end

#project_nameObject

Returns the value of attribute project_name

Returns:

  • (Object)

    the current value of project_name



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

def project_name
  @project_name
end

#sshObject

Returns the value of attribute ssh

Returns:

  • (Object)

    the current value of ssh



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

def ssh
  @ssh
end

#ssh_keyObject

Returns the value of attribute ssh_key

Returns:

  • (Object)

    the current value of ssh_key



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

def ssh_key
  @ssh_key
end

Class Method Details

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



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

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

.setting(*fields) ⇒ Object



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

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

Instance Method Details

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



112
113
114
# File 'lib/bard/server.rb', line 112

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

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



108
109
110
# File 'lib/bard/server.rb', line 108

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

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



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

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

#rsync_uri(file_path = nil) ⇒ Object



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

def rsync_uri file_path=nil
  str = ssh_uri.dup.tap do |uri|
    uri.scheme = nil
    uri.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



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

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



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

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



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

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



61
62
63
64
# File 'lib/bard/server.rb', line 61

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

#to_symObject



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

def to_sym
  key
end

#with(attrs) ⇒ Object



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

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