Top Level Namespace

Defined Under Namespace

Modules: Local Classes: Array, CheckResult, ConfigBlockHandler, LocalEntity, LocalFile, RemoteFile, TaskResult, UndefinedOnLocal

Instance Method Summary collapse

Instance Method Details

#apt_install(names) ⇒ Object



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

def apt_install(names)
  Local.type_check(nil, names, String, Symbol, Array)
  TaskResult.new
end

#apt_remove(names) ⇒ Object



104
105
106
107
# File 'lib/local_dsl.rb', line 104

def apt_remove(names)
  Local.type_check(nil, names, String, Symbol, Array)
  TaskResult.new
end

#apt_updateObject



96
97
# File 'lib/local_dsl.rb', line 96

def apt_update
end

#as(user, group: nil) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
# File 'lib/local_dsl.rb', line 182

def as(user, group: nil)
  Local.die 'nested "as" blocks are not supported' if Local.as_user_block
  Local.type_check(nil, user, String, Symbol)
  Local.type_check(nil, group, String, Symbol) if group
  Local.as_user_block = true
  begin
    yield
  ensure
    Local.as_user_block = false
  end
end

#authorize_ssh_key(user:, key:) ⇒ Object



90
91
92
93
94
# File 'lib/local_dsl.rb', line 90

def authorize_ssh_key(user:, key:)
  Local.type_check(:user, user, String, Symbol)
  Local.type_check(:key, key, String, LocalFile)
  TaskResult.new
end

#blockObject



178
179
180
# File 'lib/local_dsl.rb', line 178

def block
  yield
end

#check(message = nil) ⇒ Object



171
172
173
174
175
176
# File 'lib/local_dsl.rb', line 171

def check(message = nil)
  Local.type_check nil, message, String if message
  # NOT yielding here. Check blocks contain code
  # that works only on remote target.
  CheckResult.new(false)
end

#chmod(mode, path) ⇒ Object



141
142
143
144
145
146
147
148
# File 'lib/local_dsl.rb', line 141

def chmod(mode, path)
  Local.type_check(2, path, String)
  if mode
    Local.type_check(:mode, mode, String, Integer)
    Local.check_mode mode
  end
  TaskResult.new
end

#command(cmd, expect_status: 0) ⇒ Object



109
110
111
112
113
# File 'lib/local_dsl.rb', line 109

def command(cmd, expect_status: 0)
  Local.type_check(nil, cmd, String, Symbol, Array)
  Local.type_check(:expect_status, expect_status, Integer, Array, Range)
  TaskResult.new
end

#cp(src, dst, mode: nil) ⇒ Object



131
132
133
134
135
136
137
138
139
# File 'lib/local_dsl.rb', line 131

def cp(src, dst, mode: nil)
  Local.type_check(1, src, String, LocalFile)
  Local.type_check(1, dst, String)
  if mode
    Local.type_check(:mode, mode, String, Integer)
    Local.check_mode mode
  end
  TaskResult.new
end

#create_config(path, text) ⇒ Object



115
116
117
118
119
# File 'lib/local_dsl.rb', line 115

def create_config(path, text)
  Local.type_check(1, path, String)
  Local.type_check(2, text, String)
  TaskResult.new
end

#create_user(name, create_home:, shell:) ⇒ Object



83
84
85
86
87
88
# File 'lib/local_dsl.rb', line 83

def create_user(name, create_home:, shell:)
  Local.type_check(nil, name, String, Symbol)
  Local.type_check(:create_home, create_home, TrueClass, FalseClass)
  Local.type_check(:shell, shell, String)
  TaskResult.new
end

#edit_config(path) {|h| ... } ⇒ Object

Yields:

  • (h)


67
68
69
70
71
72
73
# File 'lib/local_dsl.rb', line 67

def edit_config(path)
  Local.type_check(nil, path, String)
  h = ConfigBlockHandler.new
  h.path = path
  yield h
  TaskResult.new
end

#ln_s(src, dst) ⇒ Object



150
151
152
153
154
# File 'lib/local_dsl.rb', line 150

def ln_s(src, dst)
  Local.type_check(1, src, String)
  Local.type_check(2, dst, String)
  TaskResult.new
end

#local(x) ⇒ Object

FIXME: unused



37
38
39
# File 'lib/local_dsl.rb', line 37

def local(x)
  LocalEntity.new(x)
end

#local_file(path) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/local_dsl.rb', line 18

def local_file(path)
  # File.expand_path("~/dir") -> "/home/user/dir"
  # File.expand_path("~/dir", "/whatever") -> "/home/user/dir" anyway
  # File.expand_path("./dir", "/specific") -> "/specific/dir"
  # File.join('/specific', '/absolute') -> "/specific/absolute"
  path = File.expand_path(path, File.dirname(ENV["_"]))
  Local.die "#{path} doesn't exists" unless File.exist? path
  Local.local_files = Local.local_files | [path]
  return LocalFile.new(path)
end

#mkdir_p(x) ⇒ Object



121
122
123
124
# File 'lib/local_dsl.rb', line 121

def mkdir_p(x)
  Local.type_check(nil, x, String, Symbol, Array)
  TaskResult.new
end

#perform!Object



218
219
220
# File 'lib/local_dsl.rb', line 218

def perform!
  Local.perform!
end

#remote_file(path) ⇒ Object



194
195
196
197
# File 'lib/local_dsl.rb', line 194

def remote_file(path)
  Local.type_check(nil, path, String)
  UndefinedOnLocal.new
end

#rm(x) ⇒ Object



126
127
128
129
# File 'lib/local_dsl.rb', line 126

def rm(x)
  Local.type_check nil, x, String
  TaskResult.new
end

#service_reload(name) ⇒ Object



75
76
77
# File 'lib/local_dsl.rb', line 75

def service_reload(name)
  Local.type_check(nil, name, String, Symbol)
end

#service_restart(name) ⇒ Object



79
80
81
# File 'lib/local_dsl.rb', line 79

def service_restart(name)
  Local.type_check(nil, name, String, Symbol)
end

#target(host:, user: nil, port: nil) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/local_dsl.rb', line 3

def target(host:, user: nil, port: nil)
  Local.type_check(:host, host, String)
  Local.type_check(:user, user, String) if user
  Local.type_check(:port, port, Integer) if port
  #Local.target = Local::DEFAULT_TARGET.dup
  Local.target[:host] = host
  Local.target[:user] = user if user
  Local.target[:port] = port if port
end