akaer 2.1.2 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,6 +15,7 @@
15
15
  <script type="text/javascript" charset="utf-8" src="js/full_list.js"></script>
16
16
 
17
17
 
18
+ <title>Method List</title>
18
19
  <base id="base_target" target="_parent" />
19
20
  </head>
20
21
  <body>
@@ -48,161 +49,121 @@
48
49
 
49
50
  <li class="r1 ">
50
51
  <span class='object_link'><a href="Akaer/Application.html#%40return-instance_method" title="Akaer::Application\#@return (method)">#@return</a></span>
51
-
52
- <small>Akaer::Application</small>
53
-
52
+ <small>Akaer::Application</small>
54
53
  </li>
55
54
 
56
55
 
57
56
  <li class="r2 ">
58
57
  <span class='object_link'><a href="Akaer/ApplicationMethods/System.html#action_add-instance_method" title="Akaer::ApplicationMethods::System#action_add (method)">#action_add</a></span>
59
-
60
- <small>Akaer::ApplicationMethods::System</small>
61
-
58
+ <small>Akaer::ApplicationMethods::System</small>
62
59
  </li>
63
60
 
64
61
 
65
62
  <li class="r1 ">
66
63
  <span class='object_link'><a href="Akaer/ApplicationMethods/System.html#action_install-instance_method" title="Akaer::ApplicationMethods::System#action_install (method)">#action_install</a></span>
67
-
68
- <small>Akaer::ApplicationMethods::System</small>
69
-
64
+ <small>Akaer::ApplicationMethods::System</small>
70
65
  </li>
71
66
 
72
67
 
73
68
  <li class="r2 ">
74
69
  <span class='object_link'><a href="Akaer/ApplicationMethods/System.html#action_remove-instance_method" title="Akaer::ApplicationMethods::System#action_remove (method)">#action_remove</a></span>
75
-
76
- <small>Akaer::ApplicationMethods::System</small>
77
-
70
+ <small>Akaer::ApplicationMethods::System</small>
78
71
  </li>
79
72
 
80
73
 
81
74
  <li class="r1 ">
82
75
  <span class='object_link'><a href="Akaer/ApplicationMethods/System.html#action_uninstall-instance_method" title="Akaer::ApplicationMethods::System#action_uninstall (method)">#action_uninstall</a></span>
83
-
84
- <small>Akaer::ApplicationMethods::System</small>
85
-
76
+ <small>Akaer::ApplicationMethods::System</small>
86
77
  </li>
87
78
 
88
79
 
89
80
  <li class="r2 ">
90
81
  <span class='object_link'><a href="Akaer/Application.html#command-instance_method" title="Akaer::Application#command (method)">#command</a></span>
91
-
92
- <small>Akaer::Application</small>
93
-
82
+ <small>Akaer::Application</small>
94
83
  </li>
95
84
 
96
85
 
97
86
  <li class="r1 ">
98
87
  <span class='object_link'><a href="Akaer/Application.html#compute_addresses-instance_method" title="Akaer::Application#compute_addresses (method)">#compute_addresses</a></span>
99
-
100
- <small>Akaer::Application</small>
101
-
88
+ <small>Akaer::Application</small>
102
89
  </li>
103
90
 
104
91
 
105
92
  <li class="r2 ">
106
93
  <span class='object_link'><a href="Akaer/Application.html#config-instance_method" title="Akaer::Application#config (method)">#config</a></span>
107
-
108
- <small>Akaer::Application</small>
109
-
94
+ <small>Akaer::Application</small>
110
95
  </li>
111
96
 
112
97
 
113
98
  <li class="r1 ">
114
99
  <span class='object_link'><a href="Akaer/Application.html#execute_command-instance_method" title="Akaer::Application#execute_command (method)">#execute_command</a></span>
115
-
116
- <small>Akaer::Application</small>
117
-
100
+ <small>Akaer::Application</small>
118
101
  </li>
119
102
 
120
103
 
121
104
  <li class="r2 ">
122
105
  <span class='object_link'><a href="Akaer/Application.html#get_logger-instance_method" title="Akaer::Application#get_logger (method)">#get_logger</a></span>
123
-
124
- <small>Akaer::Application</small>
125
-
106
+ <small>Akaer::Application</small>
126
107
  </li>
127
108
 
128
109
 
129
110
  <li class="r1 ">
130
111
  <span class='object_link'><a href="Akaer/Configuration.html#initialize-instance_method" title="Akaer::Configuration#initialize (method)">#initialize</a></span>
131
-
132
- <small>Akaer::Configuration</small>
133
-
112
+ <small>Akaer::Configuration</small>
134
113
  </li>
135
114
 
136
115
 
137
116
  <li class="r2 ">
138
117
  <span class='object_link'><a href="Akaer/Application.html#initialize-instance_method" title="Akaer::Application#initialize (method)">#initialize</a></span>
139
-
140
- <small>Akaer::Application</small>
141
-
118
+ <small>Akaer::Application</small>
142
119
  </li>
143
120
 
144
121
 
145
122
  <li class="r1 ">
146
123
  <span class='object_link'><a href="Akaer/Application.html#instance-class_method" title="Akaer::Application.instance (method)">instance</a></span>
147
-
148
- <small>Akaer::Application</small>
149
-
124
+ <small>Akaer::Application</small>
150
125
  </li>
151
126
 
152
127
 
153
128
  <li class="r2 ">
154
129
  <span class='object_link'><a href="Akaer/Application.html#is_ipv4%3F-instance_method" title="Akaer::Application#is_ipv4? (method)">#is_ipv4?</a></span>
155
-
156
- <small>Akaer::Application</small>
157
-
130
+ <small>Akaer::Application</small>
158
131
  </li>
159
132
 
160
133
 
161
134
  <li class="r1 ">
162
135
  <span class='object_link'><a href="Akaer/Application.html#is_ipv6%3F-instance_method" title="Akaer::Application#is_ipv6? (method)">#is_ipv6?</a></span>
163
-
164
- <small>Akaer::Application</small>
165
-
136
+ <small>Akaer::Application</small>
166
137
  </li>
167
138
 
168
139
 
169
140
  <li class="r2 ">
170
141
  <span class='object_link'><a href="Akaer/ApplicationMethods/General.html#is_osx%3F-instance_method" title="Akaer::ApplicationMethods::General#is_osx? (method)">#is_osx?</a></span>
171
-
172
- <small>Akaer::ApplicationMethods::General</small>
173
-
142
+ <small>Akaer::ApplicationMethods::General</small>
174
143
  </li>
175
144
 
176
145
 
177
146
  <li class="r1 ">
178
147
  <span class='object_link'><a href="Akaer/Application.html#launch_agent_path-instance_method" title="Akaer::Application#launch_agent_path (method)">#launch_agent_path</a></span>
179
-
180
- <small>Akaer::Application</small>
181
-
148
+ <small>Akaer::Application</small>
182
149
  </li>
183
150
 
184
151
 
185
152
  <li class="r2 ">
186
153
  <span class='object_link'><a href="Akaer/Application.html#logger-instance_method" title="Akaer::Application#logger (method)">#logger</a></span>
187
-
188
- <small>Akaer::Application</small>
189
-
154
+ <small>Akaer::Application</small>
190
155
  </li>
191
156
 
192
157
 
193
158
  <li class="r1 ">
194
159
  <span class='object_link'><a href="Akaer/ApplicationMethods/General.html#manage-instance_method" title="Akaer::ApplicationMethods::General#manage (method)">#manage</a></span>
195
-
196
- <small>Akaer::ApplicationMethods::General</small>
197
-
160
+ <small>Akaer::ApplicationMethods::General</small>
198
161
  </li>
199
162
 
200
163
 
201
164
  <li class="r2 ">
202
165
  <span class='object_link'><a href="Akaer/Application.html#pad_number-instance_method" title="Akaer::Application#pad_number (method)">#pad_number</a></span>
203
-
204
- <small>Akaer::Application</small>
205
-
166
+ <small>Akaer::Application</small>
206
167
  </li>
207
168
 
208
169
 
@@ -6,13 +6,13 @@
6
6
  <title>
7
7
  Top Level Namespace
8
8
 
9
- &mdash; Documentation by YARD 0.8.5.2
9
+ &mdash; Documentation by YARD 0.8.6.2
10
10
 
11
11
  </title>
12
12
 
13
- <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
14
14
 
15
- <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
16
16
 
17
17
  <script type="text/javascript" charset="utf-8">
18
18
  hasFrames = window.top.frames.main ? true : false;
@@ -103,9 +103,9 @@
103
103
  </div>
104
104
 
105
105
  <div id="footer">
106
- Generated on Sat Apr 13 12:22:51 2013 by
106
+ Generated on Sun Jul 14 17:46:44 2013 by
107
107
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
108
- 0.8.5.2 (ruby-1.9.3).
108
+ 0.8.6.2 (ruby-1.9.3).
109
109
  </div>
110
110
 
111
111
  </body>
@@ -18,7 +18,7 @@ module Akaer
18
18
  #
19
19
  # @return [Boolean] `true` if the current platform is MacOS X, `false` otherwise.
20
20
  def is_osx?
21
- ::RbConfig::CONFIG['host_os'] =~ /^darwin/
21
+ !(::RbConfig::CONFIG['host_os'] =~ /^darwin/).nil?
22
22
  end
23
23
 
24
24
  # Adds or removes an alias from the interface.
@@ -27,7 +27,7 @@ module Akaer
27
27
  # @param address [String] The address to manage.
28
28
  # @return [Boolean] `true` if operation succeeded, `false` otherwise.
29
29
  def manage(type, address)
30
- locale = self.i18n
30
+ locale = i18n
31
31
  config = self.config
32
32
  quiet = config.quiet
33
33
  rv, command, prefix = setup_management(type, address)
@@ -52,9 +52,9 @@ module Akaer
52
52
  # @return [Array] A list of parameters for the management.
53
53
  def setup_management(type, address)
54
54
  begin
55
- @addresses ||= self.compute_addresses
56
- length = self.pad_number(@addresses.length)
57
- [true, build_command(type, address), "{mark=blue}[{mark=bright white}#{self.pad_number((@addresses.index(address) || 0) + 1, length.length)}{mark=reset blue}/{/mark}#{length}{/mark}]{/mark}"]
55
+ @addresses ||= compute_addresses
56
+ length = pad_number(@addresses.length)
57
+ [true, build_command(type, address), "{mark=blue}[{mark=bright white}#{pad_number((@addresses.index(address) || 0) + 1, length.length)}{mark=reset blue}/{/mark}#{length}{/mark}]{/mark}"]
58
58
  rescue ArgumentError
59
59
  [false]
60
60
  end
@@ -79,9 +79,9 @@ module Akaer
79
79
  # @param quiet [Boolean] Whether to show the message.
80
80
  # @return [Boolean] `true` if operation succeeded, `false` otherwise.
81
81
  def execute_manage(command, prefix, type, address, config, quiet)
82
- locale = self.i18n
82
+ locale = i18n
83
83
  log_management(:run, prefix, type, locale.removing, locale.adding, address, config, quiet)
84
- rv = self.execute_command(command)
84
+ rv = execute_command(command)
85
85
  labels = (type == :remove ? [locale.remove, locale.from] : [locale.add, locale.to])
86
86
  @logger.error(@command.application.console.replace_markers(locale.general_error(labels[0], address, labels[1], config.interface))) if !rv
87
87
  rv
@@ -98,9 +98,9 @@ module Akaer
98
98
  # @param config [Configuration] The current configuration.
99
99
  # @param quiet [Boolean] Whether to show the message.
100
100
  def log_management(message, prefix, type, remove_label, add_label, address, config, quiet)
101
- locale = self.i18n
101
+ locale = i18n
102
102
  labels = (type == :remove ? [remove_label, locale.from] : [add_label, locale.to])
103
- @logger.info(@command.application.console.replace_markers(self.i18n.send(message, prefix, labels[0], address, labels[1], config.interface))) if !quiet
103
+ @logger.info(@command.application.console.replace_markers(i18n.send(message, prefix, labels[0], address, labels[1], config.interface))) if !quiet
104
104
  end
105
105
 
106
106
  # Manages an action on the request addresses.
@@ -109,13 +109,11 @@ module Akaer
109
109
  # @param message [String] The message to show if no addresses are found.
110
110
  # @param quiet [Boolean] Whether to show the failure message.
111
111
  def manage_action(operation, message, quiet)
112
- addresses = self.compute_addresses
112
+ addresses = compute_addresses
113
113
 
114
114
  if addresses.present? then
115
115
  # Now, for every address, call the command
116
- addresses.all? {|address|
117
- self.manage(operation, address)
118
- }
116
+ addresses.all? {|address| manage(operation, address) }
119
117
  else
120
118
  @logger.error(message) if !quiet
121
119
  end
@@ -128,28 +126,28 @@ module Akaer
128
126
  #
129
127
  # @return [Boolean] `true` if action succeeded, `false` otherwise.
130
128
  def action_add
131
- manage_action(:add, self.i18n.add_empty, self.config.quiet)
129
+ manage_action(:add, i18n.add_empty, config.quiet)
132
130
  end
133
131
 
134
132
  # Removes aliases from the interface.
135
133
  #
136
134
  # @return [Boolean] `true` if action succeeded, `false` otherwise.
137
135
  def action_remove
138
- manage_action(:remove, self.i18n.remove_empty, self.config.quiet)
136
+ manage_action(:remove, i18n.remove_empty, config.quiet)
139
137
  end
140
138
 
141
139
  # Installs the application into the autolaunch.
142
140
  #
143
141
  # @return [Boolean] `true` if action succeeded, `false` otherwise.
144
142
  def action_install
145
- manage_agent(self.launch_agent_path, :create_agent, :load_agent, self.config.quiet)
143
+ manage_agent(launch_agent_path, :create_agent, :load_agent, config.quiet)
146
144
  end
147
145
 
148
146
  # Uninstalls the application from the autolaunch.
149
147
  #
150
148
  # @return [Boolean] `true` if action succeeded, `false` otherwise.
151
149
  def action_uninstall
152
- manage_agent(self.launch_agent_path, :unload_agent, :delete_agent, self.config.quiet)
150
+ manage_agent(launch_agent_path, :unload_agent, :delete_agent, config.quiet)
153
151
  end
154
152
 
155
153
  private
@@ -172,13 +170,12 @@ module Akaer
172
170
  # @param quiet [Boolean] Whether to show messages.
173
171
  # @return [Boolean] `true` if the agent is enabled, `false` otherwise.
174
172
  def check_agent_available(quiet)
175
- rv = true
176
- if !self.is_osx? then
177
- logger.fatal(self.i18n.no_agent) if !quiet
178
- rv = false
173
+ if is_osx? then
174
+ true
175
+ else
176
+ logger.fatal(i18n.no_agent) if !quiet
177
+ false
179
178
  end
180
-
181
- rv
182
179
  end
183
180
 
184
181
  # Creates a OSX system agent.
@@ -188,12 +185,12 @@ module Akaer
188
185
  # @return [Boolean] `true` if operation succeeded, `false` otherwise.
189
186
  def create_agent(launch_agent, quiet)
190
187
  begin
191
- self.logger.info(self.i18n.agent_creating(launch_agent)) if !quiet
188
+ logger.info(i18n.agent_creating(launch_agent)) if !quiet
192
189
  write_agent(launch_agent)
193
- self.execute_command("plutil -convert binary1 \"#{launch_agent}\"")
190
+ execute_command("plutil -convert binary1 \"#{launch_agent}\"")
194
191
  true
195
192
  rescue
196
- self.logger.error(self.i18n.agent_creating_error) if !quiet
193
+ logger.error(i18n.agent_creating_error) if !quiet
197
194
  false
198
195
  end
199
196
  end
@@ -215,11 +212,11 @@ module Akaer
215
212
  # @return [Boolean] `true` if operation succeeded, `false` otherwise.
216
213
  def delete_agent(launch_agent, quiet)
217
214
  begin
218
- self.logger.info(self.i18n.agent_deleting(launch_agent)) if !quiet
215
+ logger.info(i18n.agent_deleting(launch_agent)) if !quiet
219
216
  ::File.delete(launch_agent)
220
217
  rescue
221
- self.logger.warn(self.i18n.agent_deleting_error) if !quiet
222
- return false
218
+ logger.warn(i18n.agent_deleting_error) if !quiet
219
+ false
223
220
  end
224
221
  end
225
222
 
@@ -229,12 +226,7 @@ module Akaer
229
226
  # @param quiet [Boolean] Whether to show messages.
230
227
  # @return [Boolean] `true` if operation succeeded, `false` otherwise.
231
228
  def load_agent(launch_agent, quiet)
232
- begin
233
- perform_agent_loading(launch_agent, "load", :agent_loading, quiet)
234
- rescue
235
- self.logger.error(self.i18n.agent_loading_error) if !quiet
236
- false
237
- end
229
+ perform_agent_loading(launch_agent, "load", :agent_loading, :agent_loading_error, quiet)
238
230
  end
239
231
 
240
232
  # Unloads a OSX system agent.
@@ -243,12 +235,7 @@ module Akaer
243
235
  # @param quiet [Boolean] Whether to show messages.
244
236
  # @return [Boolean] `true` if operation succeeded, `false` otherwise.
245
237
  def unload_agent(launch_agent, quiet)
246
- begin
247
- perform_agent_loading(launch_agent, "unload", :agent_unloading, quiet)
248
- rescue
249
- self.logger.warn(self.i18n.agent_unloading_error) if !quiet
250
- false
251
- end
238
+ perform_agent_loading(launch_agent, "unload", :agent_unloading, :agent_unloading_error, quiet)
252
239
  end
253
240
 
254
241
  # Performs operation on a OSX system agent.
@@ -256,12 +243,18 @@ module Akaer
256
243
  # @param launch_agent [String] The agent path.
257
244
  # @param command [String] The command to run.
258
245
  # @param message [String] The message to show.
246
+ # @param error_message [String] The error message to show.
259
247
  # @param quiet [Boolean] Whether to show messages.
260
248
  # @return [Boolean] `true` if operation succeeded, `false` otherwise.
261
- def perform_agent_loading(launch_agent, command, message, quiet)
262
- self.logger.info(self.i18n.send(message, launch_agent)) if !quiet
263
- self.execute_command("launchctl #{command} -w \"#{launch_agent}\" > /dev/null 2>&1")
264
- true
249
+ def perform_agent_loading(launch_agent, command, message, error_message, quiet)
250
+ begin
251
+ logger.info(i18n.send(message, launch_agent)) if !quiet
252
+ execute_command("launchctl #{command} -w \"#{launch_agent}\" > /dev/null 2>&1")
253
+ true
254
+ rescue
255
+ logger.send(command == "load" ? :error : :warn, i18n.send(error_message)) if !quiet
256
+ false
257
+ end
265
258
  end
266
259
  end
267
260
  end
@@ -288,7 +281,7 @@ module Akaer
288
281
  # @param command [Mamertes::Command] The current Mamertes command.
289
282
  # @param locale [Symbol] The locale to use for the application.
290
283
  def initialize(command, locale)
291
- self.i18n_setup(:akaer, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/"))
284
+ i18n_setup(:akaer, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/"))
292
285
  self.i18n = locale
293
286
 
294
287
  @command = command
@@ -328,9 +321,9 @@ module Akaer
328
321
  throw(:valid, true) if /\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*)?\Z/ =~ address
329
322
  throw(:valid, true) if /\A::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*)?\Z/ =~ address
330
323
  # IPv6 (IPv4 compat)
331
- throw(:valid, true) if /\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:/ =~ address && self.is_ipv4?($')
332
- throw(:valid, true) if /\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:)?/ =~ address && self.is_ipv4?($')
333
- throw(:valid, true) if /\A::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:)?/ =~ address && self.is_ipv4?($')
324
+ throw(:valid, true) if /\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:/ =~ address && is_ipv4?($')
325
+ throw(:valid, true) if /\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:)?/ =~ address && is_ipv4?($')
326
+ throw(:valid, true) if /\A::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:)?/ =~ address && is_ipv4?($')
334
327
 
335
328
  false
336
329
  end
@@ -397,9 +390,9 @@ module Akaer
397
390
  begin
398
391
  @config = Akaer::Configuration.new(options["configuration"], options, @logger)
399
392
  @logger = nil
400
- @logger = self.get_logger
393
+ @logger = get_logger
401
394
  rescue Bovem::Errors::InvalidConfiguration => e
402
- @logger ? @logger.fatal(e.message) : Bovem::Logger.create("STDERR").fatal(self.i18n.logging_failed(log_file))
395
+ @logger ? @logger.fatal(e.message) : Bovem::Logger.create("STDERR").fatal(i18n.logging_failed(log_file))
403
396
  raise ::SystemExit
404
397
  end
405
398
  end
@@ -413,7 +406,7 @@ module Akaer
413
406
  filters = [:ipv4, :ipv6].select {|i| type == i || type == :all }.compact
414
407
 
415
408
  config.addresses.select { |address|
416
- filters.any? {|filter| self.send("is_#{filter}?", address) }
409
+ filters.any? {|filter| send("is_#{filter}?", address) }
417
410
  }.compact.uniq
418
411
  end
419
412