Top Level Namespace

Defined Under Namespace

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

Instance Method Summary collapse

Instance Method Details

#apt_install(names) ⇒ Object



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

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

#apt_remove(names) ⇒ Object



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

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

#apt_updateObject



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

def apt_update
end

#as(user, group: nil) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
# File 'lib/local_dsl.rb', line 154

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



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

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

#blockObject



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

def block
  yield
end

#chmod(mode, path) ⇒ Object



135
136
137
138
139
140
141
142
# File 'lib/local_dsl.rb', line 135

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



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

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



125
126
127
128
129
130
131
132
133
# File 'lib/local_dsl.rb', line 125

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



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

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



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

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)


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

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



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

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

#local(x) ⇒ Object



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

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

#local_file(path) ⇒ Object



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

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



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

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

#perform!Object



190
191
192
# File 'lib/local_dsl.rb', line 190

def perform!
  Local.perform!
end

#remote_file(path) ⇒ Object



166
167
168
169
# File 'lib/local_dsl.rb', line 166

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

#service_reload(name) ⇒ Object



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

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

#service_restart(name) ⇒ Object



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

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

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



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

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