aruba-win-fix 0.14.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.gitignore +37 -0
- data/.rspec +3 -0
- data/.rubocop.yml +188 -0
- data/.simplecov +34 -0
- data/.travis.yml +47 -0
- data/.yardopts +8 -0
- data/CONTRIBUTING.md +71 -0
- data/Gemfile +83 -0
- data/History.md +579 -0
- data/LICENSE +20 -0
- data/README.md +226 -0
- data/Rakefile +49 -0
- data/TODO.md +13 -0
- data/appveyor.yml +32 -0
- data/aruba.gemspec +48 -0
- data/bin/aruba +7 -0
- data/config/.gitignore +1 -0
- data/cucumber.yml +26 -0
- data/features/.nav +72 -0
- data/features/api/command/find_command.feature +83 -0
- data/features/api/command/last_command_started.feature +50 -0
- data/features/api/command/last_command_stopped.feature +89 -0
- data/features/api/command/run.feature +414 -0
- data/features/api/command/run_simple.feature +242 -0
- data/features/api/command/send_signal.feature +53 -0
- data/features/api/command/stderr.feature +46 -0
- data/features/api/command/stdout.feature +46 -0
- data/features/api/command/stop.feature +131 -0
- data/features/api/command/stop_all_commands.feature +53 -0
- data/features/api/command/terminate_all_commands.feature +53 -0
- data/features/api/command/which.feature +37 -0
- data/features/api/core/expand_path.feature +88 -0
- data/features/api/environment/append_environment_variable.feature +128 -0
- data/features/api/environment/delete_environment_variable.feature +63 -0
- data/features/api/environment/prepend_environment_variable.feature +128 -0
- data/features/api/environment/set_environment_variable.feature +376 -0
- data/features/api/filesystem/cd.feature +184 -0
- data/features/api/filesystem/create_directory.feature +57 -0
- data/features/api/filesystem/disk_usage.feature +152 -0
- data/features/api/filesystem/does_exist.feature +62 -0
- data/features/api/filesystem/fixtures.feature +104 -0
- data/features/api/filesystem/is_absolute.feature +48 -0
- data/features/api/filesystem/is_directory.feature +53 -0
- data/features/api/filesystem/is_file.feature +54 -0
- data/features/api/filesystem/is_relative.feature +48 -0
- data/features/api/filesystem/move.feature +119 -0
- data/features/api/text/extract_text.feature +87 -0
- data/features/api/text/replace_variables.feature +45 -0
- data/features/api/text/sanitize_text.feature +228 -0
- data/features/api/text/unescape_text.feature +127 -0
- data/features/cli/console.feature +52 -0
- data/features/cli/init.feature +79 -0
- data/features/configuration/activate_announcer_on_command_failure.feature +38 -0
- data/features/configuration/command_runtime_environment.feature +129 -0
- data/features/configuration/console_history_file.feature +38 -0
- data/features/configuration/exit_timeout.feature +52 -0
- data/features/configuration/fixtures_directories.feature +38 -0
- data/features/configuration/fixtures_path_prefix.feature +23 -0
- data/features/configuration/home_directory.feature +80 -0
- data/features/configuration/io_timeout.feature +30 -0
- data/features/configuration/keep_ansi.feature +30 -0
- data/features/configuration/log_level.feature +38 -0
- data/features/configuration/physical_block_size.feature +53 -0
- data/features/configuration/remove_ansi_escape_sequences.feature +38 -0
- data/features/configuration/root_directory.feature +30 -0
- data/features/configuration/startup_wait_time.feature +48 -0
- data/features/configuration/usage.feature +159 -0
- data/features/configuration/working_directory.feature +33 -0
- data/features/development/build.feature +15 -0
- data/features/development/test.feature +24 -0
- data/features/getting_started/cleanup.feature +67 -0
- data/features/getting_started/install.feature +8 -0
- data/features/getting_started/run_commands.feature +177 -0
- data/features/getting_started/supported_testing_frameworks.feature +104 -0
- data/features/getting_started/writing_good_feature_tests.feature +38 -0
- data/features/hooks/after/command.feature +44 -0
- data/features/hooks/before/command.feature +71 -0
- data/features/matchers/collection/include_an_object.feature +72 -0
- data/features/matchers/directory/have_sub_directory.feature +110 -0
- data/features/matchers/file/be_a_command_found_in_path.feature +115 -0
- data/features/matchers/file/be_existing_executable.feature +88 -0
- data/features/matchers/file/be_existing_file.feature +82 -0
- data/features/matchers/file/have_file_content.feature +123 -0
- data/features/matchers/file/have_file_size.feature +107 -0
- data/features/matchers/path/be_an_absolute_path.feature +74 -0
- data/features/matchers/path/be_an_existing_path.feature +97 -0
- data/features/matchers/path/have_permissions.feature +118 -0
- data/features/matchers/timeouts.feature +48 -0
- data/features/platforms/jruby.feature +14 -0
- data/features/rspec/integration.feature +179 -0
- data/features/step_definitions/aruba_dev_steps.rb +56 -0
- data/features/step_definitions/hooks.rb +96 -0
- data/features/steps/command/debug.feature +92 -0
- data/features/steps/command/exit_statuses.feature +136 -0
- data/features/steps/command/in_process.feature +485 -0
- data/features/steps/command/interactive.feature +90 -0
- data/features/steps/command/output.feature +588 -0
- data/features/steps/command/run.feature +66 -0
- data/features/steps/command/send_signal.feature +104 -0
- data/features/steps/command/shell.feature +155 -0
- data/features/steps/command/stderr.feature +68 -0
- data/features/steps/command/stdout.feature +109 -0
- data/features/steps/command/stop.feature +313 -0
- data/features/steps/core/announce.feature +283 -0
- data/features/steps/environment/append_environment_variable.feature +52 -0
- data/features/steps/environment/home_variable.feature +62 -0
- data/features/steps/environment/prepend_environment_variable.feature +52 -0
- data/features/steps/environment/set_environment_variable.feature +49 -0
- data/features/steps/filesystem/append_to_file.feature +45 -0
- data/features/steps/filesystem/cd_to_directory.feature +33 -0
- data/features/steps/filesystem/check_file_content.feature +61 -0
- data/features/steps/filesystem/check_permissions_of_file.feature +39 -0
- data/features/steps/filesystem/compare_files.feature +42 -0
- data/features/steps/filesystem/copy.feature +45 -0
- data/features/steps/filesystem/create_directory.feature +57 -0
- data/features/steps/filesystem/create_file.feature +76 -0
- data/features/steps/filesystem/existence_of_directory.feature +57 -0
- data/features/steps/filesystem/existence_of_file.feature +43 -0
- data/features/steps/filesystem/file_content.feature +86 -0
- data/features/steps/filesystem/fixtures.feature +64 -0
- data/features/steps/filesystem/move.feature +45 -0
- data/features/steps/filesystem/non_existence_of_directory.feature +69 -0
- data/features/steps/filesystem/non_existence_of_file.feature +80 -0
- data/features/steps/filesystem/overwrite_file.feature +72 -0
- data/features/steps/filesystem/remove_directory.feature +38 -0
- data/features/steps/filesystem/remove_file.feature +38 -0
- data/features/steps/filesystem/use_fixture.feature +77 -0
- data/features/steps/overview.feature +60 -0
- data/features/support/aruba.rb +7 -0
- data/features/support/env.rb +33 -0
- data/features/support/jruby.rb +5 -0
- data/features/support/simplecov_setup.rb +8 -0
- data/fixtures/cli-app/.gitignore +9 -0
- data/fixtures/cli-app/.rspec +2 -0
- data/fixtures/cli-app/README.md +39 -0
- data/fixtures/cli-app/Rakefile +1 -0
- data/fixtures/cli-app/bin/cli +6 -0
- data/fixtures/cli-app/cli-app.gemspec +26 -0
- data/fixtures/cli-app/features/support/env.rb +1 -0
- data/fixtures/cli-app/lib/cli/app.rb +13 -0
- data/fixtures/cli-app/lib/cli/app/suppress_simple_cov_output.rb +15 -0
- data/fixtures/cli-app/lib/cli/app/version.rb +5 -0
- data/fixtures/cli-app/script/console +14 -0
- data/fixtures/cli-app/spec/spec_helper.rb +9 -0
- data/fixtures/cli-app/spec/support/aruba.rb +1 -0
- data/fixtures/copy/file.txt +1 -0
- data/fixtures/empty-app/.gitignore +9 -0
- data/fixtures/empty-app/.rspec +2 -0
- data/fixtures/empty-app/README.md +24 -0
- data/fixtures/empty-app/Rakefile +1 -0
- data/fixtures/empty-app/cli-app.gemspec +26 -0
- data/fixtures/empty-app/lib/cli/app.rb +13 -0
- data/fixtures/empty-app/lib/cli/app/version.rb +5 -0
- data/fixtures/getting-started-app/.gitignore +4 -0
- data/fixtures/getting-started-app/Gemfile +4 -0
- data/fixtures/getting-started-app/README.md +3 -0
- data/fixtures/getting-started-app/features/support/env.rb +1 -0
- data/fixtures/spawn_process/stderr.sh +3 -0
- data/lib/aruba.rb +1 -0
- data/lib/aruba/api.rb +34 -0
- data/lib/aruba/api/command.rb +307 -0
- data/lib/aruba/api/core.rb +191 -0
- data/lib/aruba/api/deprecated.rb +897 -0
- data/lib/aruba/api/environment.rb +89 -0
- data/lib/aruba/api/filesystem.rb +392 -0
- data/lib/aruba/api/rvm.rb +44 -0
- data/lib/aruba/api/text.rb +56 -0
- data/lib/aruba/aruba_path.rb +133 -0
- data/lib/aruba/basic_configuration.rb +240 -0
- data/lib/aruba/basic_configuration/option.rb +32 -0
- data/lib/aruba/cli.rb +26 -0
- data/lib/aruba/colorizer.rb +108 -0
- data/lib/aruba/command.rb +74 -0
- data/lib/aruba/config.rb +108 -0
- data/lib/aruba/config/jruby.rb +17 -0
- data/lib/aruba/config_wrapper.rb +58 -0
- data/lib/aruba/console.rb +70 -0
- data/lib/aruba/console/help.rb +35 -0
- data/lib/aruba/contracts/absolute_path.rb +20 -0
- data/lib/aruba/contracts/enum.rb +26 -0
- data/lib/aruba/contracts/is_power_of_two.rb +22 -0
- data/lib/aruba/contracts/relative_path.rb +20 -0
- data/lib/aruba/cucumber.rb +13 -0
- data/lib/aruba/cucumber/command.rb +422 -0
- data/lib/aruba/cucumber/core.rb +5 -0
- data/lib/aruba/cucumber/environment.rb +42 -0
- data/lib/aruba/cucumber/file.rb +201 -0
- data/lib/aruba/cucumber/hooks.rb +160 -0
- data/lib/aruba/cucumber/rvm.rb +3 -0
- data/lib/aruba/cucumber/testing_frameworks.rb +95 -0
- data/lib/aruba/errors.rb +37 -0
- data/lib/aruba/event_bus.rb +59 -0
- data/lib/aruba/event_bus/name_resolver.rb +168 -0
- data/lib/aruba/events.rb +39 -0
- data/lib/aruba/extensions/string/strip.rb +25 -0
- data/lib/aruba/file_size.rb +63 -0
- data/lib/aruba/generators/script_file.rb +46 -0
- data/lib/aruba/hooks.rb +56 -0
- data/lib/aruba/in_config_wrapper.rb +24 -0
- data/lib/aruba/in_process.rb +14 -0
- data/lib/aruba/initializer.rb +222 -0
- data/lib/aruba/jruby.rb +4 -0
- data/lib/aruba/matchers/base/base_matcher.rb +96 -0
- data/lib/aruba/matchers/base/object_formatter.rb +114 -0
- data/lib/aruba/matchers/collection.rb +1 -0
- data/lib/aruba/matchers/collection/all.rb +11 -0
- data/lib/aruba/matchers/collection/include_an_object.rb +122 -0
- data/lib/aruba/matchers/command.rb +1 -0
- data/lib/aruba/matchers/command/be_successfully_executed.rb +34 -0
- data/lib/aruba/matchers/command/have_exit_status.rb +38 -0
- data/lib/aruba/matchers/command/have_finished_in_time.rb +37 -0
- data/lib/aruba/matchers/command/have_output.rb +36 -0
- data/lib/aruba/matchers/command/have_output_on_stderr.rb +32 -0
- data/lib/aruba/matchers/command/have_output_on_stdout.rb +32 -0
- data/lib/aruba/matchers/command/have_output_size.rb +28 -0
- data/lib/aruba/matchers/directory.rb +1 -0
- data/lib/aruba/matchers/directory/be_an_existing_directory.rb +38 -0
- data/lib/aruba/matchers/directory/have_sub_directory.rb +53 -0
- data/lib/aruba/matchers/environment.rb +1 -0
- data/lib/aruba/matchers/file.rb +1 -0
- data/lib/aruba/matchers/file/be_a_command_found_in_path.rb +36 -0
- data/lib/aruba/matchers/file/be_an_existing_executable.rb +37 -0
- data/lib/aruba/matchers/file/be_an_existing_file.rb +38 -0
- data/lib/aruba/matchers/file/have_file_content.rb +62 -0
- data/lib/aruba/matchers/file/have_file_size.rb +47 -0
- data/lib/aruba/matchers/file/have_same_file_content.rb +48 -0
- data/lib/aruba/matchers/path.rb +1 -0
- data/lib/aruba/matchers/path/a_path_matching_pattern.rb +25 -0
- data/lib/aruba/matchers/path/be_an_absolute_path.rb +36 -0
- data/lib/aruba/matchers/path/be_an_existing_path.rb +37 -0
- data/lib/aruba/matchers/path/have_permissions.rb +64 -0
- data/lib/aruba/matchers/path/match_path_pattern.rb +41 -0
- data/lib/aruba/matchers/rspec_matcher_include_regexp.rb +25 -0
- data/lib/aruba/matchers/string.rb +1 -0
- data/lib/aruba/matchers/string/include_output_string.rb +36 -0
- data/lib/aruba/matchers/string/match_output_string.rb +37 -0
- data/lib/aruba/matchers/string/output_string_eq.rb +35 -0
- data/lib/aruba/platform.rb +25 -0
- data/lib/aruba/platforms/announcer.rb +232 -0
- data/lib/aruba/platforms/aruba_file_creator.rb +35 -0
- data/lib/aruba/platforms/aruba_fixed_size_file_creator.rb +35 -0
- data/lib/aruba/platforms/aruba_logger.rb +81 -0
- data/lib/aruba/platforms/command_monitor.rb +229 -0
- data/lib/aruba/platforms/determine_disk_usage.rb +28 -0
- data/lib/aruba/platforms/determine_file_size.rb +22 -0
- data/lib/aruba/platforms/disk_usage_calculator.rb +20 -0
- data/lib/aruba/platforms/filesystem_status.rb +68 -0
- data/lib/aruba/platforms/local_environment.rb +29 -0
- data/lib/aruba/platforms/simple_table.rb +54 -0
- data/lib/aruba/platforms/unix_command_string.rb +27 -0
- data/lib/aruba/platforms/unix_environment_variables.rb +220 -0
- data/lib/aruba/platforms/unix_platform.rb +276 -0
- data/lib/aruba/platforms/unix_which.rb +85 -0
- data/lib/aruba/platforms/windows_command_string.rb +31 -0
- data/lib/aruba/platforms/windows_environment_variables.rb +89 -0
- data/lib/aruba/platforms/windows_platform.rb +42 -0
- data/lib/aruba/platforms/windows_which.rb +106 -0
- data/lib/aruba/processes/basic_process.rb +143 -0
- data/lib/aruba/processes/debug_process.rb +69 -0
- data/lib/aruba/processes/in_process.rb +125 -0
- data/lib/aruba/processes/spawn_process.rb +278 -0
- data/lib/aruba/reporting.rb +126 -0
- data/lib/aruba/rspec.rb +107 -0
- data/lib/aruba/runtime.rb +96 -0
- data/lib/aruba/setup.rb +90 -0
- data/lib/aruba/spawn_process.rb +11 -0
- data/lib/aruba/version.rb +3 -0
- data/script/bootstrap +28 -0
- data/script/console +16 -0
- data/script/test +3 -0
- data/spec/aruba/api/environment/restore_env_spec.rb +65 -0
- data/spec/aruba/api/environment/set_env_spec.rb +42 -0
- data/spec/aruba/api/filesystem/file_size_spec.rb +28 -0
- data/spec/aruba/api/runtime_spec.rb +28 -0
- data/spec/aruba/api_spec.rb +1209 -0
- data/spec/aruba/aruba_path_spec.rb +103 -0
- data/spec/aruba/basic_configuration_spec.rb +5 -0
- data/spec/aruba/configuration_spec.rb +5 -0
- data/spec/aruba/hooks_spec.rb +17 -0
- data/spec/aruba/in_config_wrapper_spec.rb +25 -0
- data/spec/aruba/jruby_spec.rb +55 -0
- data/spec/aruba/matchers/command/have_output_size_spec.rb +25 -0
- data/spec/aruba/matchers/command_spec.rb +174 -0
- data/spec/aruba/matchers/directory_spec.rb +57 -0
- data/spec/aruba/matchers/file_spec.rb +127 -0
- data/spec/aruba/matchers/path_spec.rb +88 -0
- data/spec/aruba/platform/simple_table_spec.rb +23 -0
- data/spec/aruba/platform/windows_environment_variables_spec.rb +500 -0
- data/spec/aruba/rspec_spec.rb +15 -0
- data/spec/aruba/runtime_spec.rb +29 -0
- data/spec/aruba/spawn_process_spec.rb +60 -0
- data/spec/event_bus/name_resolver_spec.rb +68 -0
- data/spec/event_bus_spec.rb +160 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/support/configs/.keep +0 -0
- data/spec/support/configs/aruba.rb +5 -0
- data/spec/support/configs/pry.rb +3 -0
- data/spec/support/configs/rspec.rb +15 -0
- data/spec/support/helpers/.keep +0 -0
- data/spec/support/helpers/reporting.rb +44 -0
- data/spec/support/matchers/.keep +0 -0
- data/spec/support/matchers/option.rb +35 -0
- data/spec/support/shared_contexts/.keep +0 -0
- data/spec/support/shared_contexts/aruba.rb +48 -0
- data/spec/support/shared_examples/.keep +0 -0
- data/spec/support/shared_examples/configuration.rb +116 -0
- data/spec/support/shared_examples/directory.rb +7 -0
- data/spec/support/shared_examples/file.rb +7 -0
- data/templates/css/console.css +24 -0
- data/templates/css/filesystem.css +42 -0
- data/templates/css/pygments-autumn.css +59 -0
- data/templates/files.erb +14 -0
- data/templates/images/LICENSE +22 -0
- data/templates/images/folder.png +0 -0
- data/templates/images/page_white.png +0 -0
- data/templates/images/page_white_gherkin.png +0 -0
- data/templates/images/page_white_ruby.png +0 -0
- data/templates/index.erb +20 -0
- data/templates/js/filesystem.js +5 -0
- data/templates/js/jquery-1.11.3.min.js +5 -0
- data/templates/main.erb +34 -0
- metadata +629 -0
data/lib/aruba/errors.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module Aruba
|
2
|
+
# Standard error
|
3
|
+
class Error < StandardError; end
|
4
|
+
|
5
|
+
# An error because a user of the API did something wrong
|
6
|
+
class UserError < StandardError; end
|
7
|
+
|
8
|
+
# Raised on launch error
|
9
|
+
class LaunchError < Error; end
|
10
|
+
|
11
|
+
# Raised if one tries to use an unknown configuration option
|
12
|
+
class UnknownOptionError < ArgumentError; end
|
13
|
+
|
14
|
+
# Raised if command already died
|
15
|
+
class CommandAlreadyStoppedError < Error; end
|
16
|
+
|
17
|
+
# Raised if one tries to access last command started, but no command
|
18
|
+
# has been started
|
19
|
+
class NoCommandHasBeenStartedError < Error; end
|
20
|
+
|
21
|
+
# Raised if one tries to access last command stopped, but no command
|
22
|
+
# has been stopped
|
23
|
+
class NoCommandHasBeenStoppedError < Error; end
|
24
|
+
|
25
|
+
# Raised if one looked for a command, but no matching was found
|
26
|
+
class CommandNotFoundError < ArgumentError; end
|
27
|
+
|
28
|
+
# Raised if command was already started, otherwise aruba forgets about the
|
29
|
+
# previous pid and you've got hidden commands run
|
30
|
+
class CommandAlreadyStartedError < Error; end
|
31
|
+
|
32
|
+
# Raised if an event name cannot be resolved
|
33
|
+
class EventNameResolveError < StandardError; end
|
34
|
+
|
35
|
+
# Raised if given object is not an event
|
36
|
+
class NoEventError < StandardError; end
|
37
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'aruba/event_bus/name_resolver'
|
2
|
+
require 'aruba/errors'
|
3
|
+
|
4
|
+
module Aruba
|
5
|
+
# Event bus
|
6
|
+
#
|
7
|
+
# Implements and in-process pub-sub events broadcaster allowing multiple observers
|
8
|
+
# to subscribe to different events that fire as your tests are executed.
|
9
|
+
#
|
10
|
+
class EventBus
|
11
|
+
# Create EventBus
|
12
|
+
#
|
13
|
+
# @param [#transform] resolver
|
14
|
+
# A resolver which transforms Symbol, String, Class into an event Class.
|
15
|
+
def initialize(resolver)
|
16
|
+
@resolver = resolver
|
17
|
+
@handlers = Hash.new { |h, k| h[k] = [] }
|
18
|
+
end
|
19
|
+
|
20
|
+
# Register for an event
|
21
|
+
#
|
22
|
+
# @param [String, Symbol, Class, Array] event_ids
|
23
|
+
# If Array, register multiple events witht the same handler. If String,
|
24
|
+
# Symbol, Class register handler for given event.
|
25
|
+
#
|
26
|
+
# @param [#call] handler_object
|
27
|
+
# The handler object, needs to have method `#call`. Either
|
28
|
+
# `handler_object` or `block` can be defined. The handler object gets the
|
29
|
+
# event passed to `#call`.
|
30
|
+
#
|
31
|
+
# @yield
|
32
|
+
# Handler block which gets the event passed as parameter.
|
33
|
+
def register(event_ids, handler_object = nil, &handler_proc)
|
34
|
+
handler = handler_proc || handler_object
|
35
|
+
|
36
|
+
fail ArgumentError, 'Please pass either an object#call or a handler block' if handler.nil? || !handler.respond_to?(:call)
|
37
|
+
|
38
|
+
Array(event_ids).flatten.each do |id|
|
39
|
+
@handlers[
|
40
|
+
@resolver.transform(id).to_s
|
41
|
+
] << handler
|
42
|
+
end
|
43
|
+
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
|
47
|
+
# Broadcast an event
|
48
|
+
#
|
49
|
+
# @param [Object] event
|
50
|
+
# An object of registered event class. This object is passed to the event
|
51
|
+
# handler.
|
52
|
+
#
|
53
|
+
def notify(event)
|
54
|
+
fail NoEventError, 'Please pass an event object, not a class' if event.is_a?(Class)
|
55
|
+
|
56
|
+
@handlers[event.class.to_s].each { |handler| handler.call(event) }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
require 'aruba/errors'
|
2
|
+
|
3
|
+
# Event notification library
|
4
|
+
module Aruba
|
5
|
+
# EventBus
|
6
|
+
class EventBus
|
7
|
+
# Resolve name to Event name
|
8
|
+
class NameResolver
|
9
|
+
# @private
|
10
|
+
# Helpers for Resolvers
|
11
|
+
module ResolveHelpers
|
12
|
+
def camel_case(underscored_name)
|
13
|
+
if RUBY_VERSION < '1.9.3'
|
14
|
+
underscored_name.to_s.split('_').map { |word| word.upcase.chars.to_a[0] + word.chars.to_a[1..-1].join }.join
|
15
|
+
else
|
16
|
+
underscored_name.to_s.split('_').map { |word| word.upcase[0] + word[1..-1] }.join
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Thanks ActiveSupport
|
21
|
+
# (Only needed to support Ruby 1.9.3 and JRuby)
|
22
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
23
|
+
# rubocop:disable Metrics/MethodLength
|
24
|
+
def constantize(camel_cased_word)
|
25
|
+
names = camel_cased_word.split('::')
|
26
|
+
|
27
|
+
# Trigger a built-in NameError exception including the ill-formed constant in the message.
|
28
|
+
Object.const_get(camel_cased_word) if names.empty?
|
29
|
+
|
30
|
+
# Remove the first blank element in case of '::ClassName' notation.
|
31
|
+
names.shift if names.size > 1 && names.first.empty?
|
32
|
+
|
33
|
+
names.inject(Object) do |constant, name|
|
34
|
+
if constant == Object
|
35
|
+
constant.const_get(name)
|
36
|
+
else
|
37
|
+
candidate = constant.const_get(name)
|
38
|
+
|
39
|
+
if RUBY_VERSION < '1.9.3'
|
40
|
+
next candidate if constant.const_defined?(name)
|
41
|
+
else
|
42
|
+
next candidate if constant.const_defined?(name, false)
|
43
|
+
end
|
44
|
+
|
45
|
+
next candidate unless Object.const_defined?(name)
|
46
|
+
|
47
|
+
# Go down the ancestors to check if it is owned directly. The check
|
48
|
+
# stops when we reach Object or the end of ancestors tree.
|
49
|
+
# rubocop:disable Style/EachWithObject
|
50
|
+
constant = constant.ancestors.inject do |const, ancestor|
|
51
|
+
break const if ancestor == Object
|
52
|
+
break ancestor if ancestor.const_defined?(name, false)
|
53
|
+
const
|
54
|
+
end
|
55
|
+
# rubocop:enable Style/EachWithObject
|
56
|
+
|
57
|
+
# owner is in Object, so raise
|
58
|
+
constant.const_get(name, false)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
63
|
+
# rubocop:enable Metrics/MethodLength
|
64
|
+
end
|
65
|
+
|
66
|
+
# @private
|
67
|
+
# Convert a class in to an event class
|
68
|
+
class ClassResolver
|
69
|
+
class << self
|
70
|
+
def match?(event_id)
|
71
|
+
event_id.is_a? Class
|
72
|
+
end
|
73
|
+
|
74
|
+
# Which types are supported
|
75
|
+
def supports
|
76
|
+
[Class]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def transform(_, event_id)
|
81
|
+
event_id
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# @private
|
86
|
+
# Convert a string in to an event class
|
87
|
+
class StringResolver
|
88
|
+
include ResolveHelpers
|
89
|
+
|
90
|
+
class << self
|
91
|
+
def match?(event_id)
|
92
|
+
event_id.is_a? String
|
93
|
+
end
|
94
|
+
|
95
|
+
# Which types are supported
|
96
|
+
def supports
|
97
|
+
[String]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def transform(_, event_id)
|
102
|
+
constantize(event_id)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# @private
|
107
|
+
# Convert a symbol in to an event class
|
108
|
+
class SymbolResolver
|
109
|
+
include ResolveHelpers
|
110
|
+
|
111
|
+
class << self
|
112
|
+
def match?(event_id)
|
113
|
+
event_id.is_a? Symbol
|
114
|
+
end
|
115
|
+
|
116
|
+
# Which types are supported
|
117
|
+
def supports
|
118
|
+
[Symbol]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def transform(default_namespace, event_id)
|
123
|
+
constantize("#{default_namespace}::#{camel_case(event_id)}")
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# @private
|
128
|
+
# Default failing resolver
|
129
|
+
#
|
130
|
+
# This comes into play if the user passes an invalid event type
|
131
|
+
class FailingResolver
|
132
|
+
class << self
|
133
|
+
def match?(event_id)
|
134
|
+
fail ArgumentError, %(Input type "#{event_id.class}" of event_id "#{event_id}" is invalid)
|
135
|
+
end
|
136
|
+
|
137
|
+
def supports
|
138
|
+
[]
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
protected
|
144
|
+
|
145
|
+
attr_reader :resolvers, :default_namespace
|
146
|
+
|
147
|
+
public
|
148
|
+
|
149
|
+
def initialize(default_namespace)
|
150
|
+
@default_namespace = default_namespace
|
151
|
+
|
152
|
+
@resolvers = []
|
153
|
+
@resolvers << ClassResolver
|
154
|
+
@resolvers << StringResolver
|
155
|
+
@resolvers << SymbolResolver
|
156
|
+
@resolvers << FailingResolver
|
157
|
+
end
|
158
|
+
|
159
|
+
def transform(event_id)
|
160
|
+
resolvers.find { |r| r.match? event_id }.new.transform(default_namespace, event_id)
|
161
|
+
rescue => e
|
162
|
+
# rubocop:disable Metrics/LineLength
|
163
|
+
raise EventNameResolveError, %(Transforming "#{event_id}" into an event class failed. Supported types are: #{@resolvers.map(&:supports).flatten.join(', ')}. #{e.message}.\n\n#{e.backtrace.join("\n")})
|
164
|
+
# rubocop:enable Metrics/LineLength
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
data/lib/aruba/events.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Aruba
|
2
|
+
module Aruba
|
3
|
+
# Events
|
4
|
+
module Events
|
5
|
+
# Basic event
|
6
|
+
#
|
7
|
+
# This is not meant for direct use - BasicEvent.new - by users. It is inherited by normal events
|
8
|
+
#
|
9
|
+
# @private
|
10
|
+
class BasicEvent
|
11
|
+
attr_reader :entity
|
12
|
+
|
13
|
+
def initialize(entity)
|
14
|
+
@entity = entity
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Command was stopped
|
19
|
+
class CommandStopped < BasicEvent; end
|
20
|
+
|
21
|
+
# Command was started
|
22
|
+
class CommandStarted < BasicEvent; end
|
23
|
+
|
24
|
+
# An environment variable was changed
|
25
|
+
class ChangedEnvironmentVariable < BasicEvent; end
|
26
|
+
|
27
|
+
# An environment variable was added
|
28
|
+
class AddedEnvironmentVariable < BasicEvent; end
|
29
|
+
|
30
|
+
# An environment variable was deleted
|
31
|
+
class DeletedEnvironmentVariable < BasicEvent; end
|
32
|
+
|
33
|
+
# The working directory has changed
|
34
|
+
class ChangedWorkingDirectory < BasicEvent; end
|
35
|
+
|
36
|
+
# The configuration was changed
|
37
|
+
class ChangedConfiguration < BasicEvent; end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# String
|
2
|
+
class String
|
3
|
+
# Strips indentation in heredocs.
|
4
|
+
#
|
5
|
+
# For example in
|
6
|
+
#
|
7
|
+
# if options[:usage]
|
8
|
+
# puts <<-USAGE.strip_heredoc
|
9
|
+
# This command does such and such.
|
10
|
+
#
|
11
|
+
# Supported options are:
|
12
|
+
# -h This message
|
13
|
+
# ...
|
14
|
+
# USAGE
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# the user would see the usage message aligned against the left margin.
|
18
|
+
#
|
19
|
+
# Technically, it looks for the least indented line in the whole string, and removes
|
20
|
+
# that amount of leading whitespace.
|
21
|
+
def strip_heredoc
|
22
|
+
indent = scan(/^[ \t]*(?=\S)/).min.to_s.size
|
23
|
+
gsub(/^[ \t]{#{indent}}/, '')
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
|
3
|
+
# Aruba
|
4
|
+
module Aruba
|
5
|
+
# File Size
|
6
|
+
class FileSize
|
7
|
+
include Comparable
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
attr_reader :bytes, :divisor
|
12
|
+
|
13
|
+
public
|
14
|
+
|
15
|
+
# Create file size object
|
16
|
+
def initialize(bytes)
|
17
|
+
@bytes = bytes
|
18
|
+
@divisor = 1024
|
19
|
+
end
|
20
|
+
|
21
|
+
# Convert to bytes
|
22
|
+
def to_byte
|
23
|
+
bytes
|
24
|
+
end
|
25
|
+
alias to_i to_byte
|
26
|
+
|
27
|
+
# Convert to float
|
28
|
+
def to_f
|
29
|
+
to_i.to_f
|
30
|
+
end
|
31
|
+
|
32
|
+
# Convert to string
|
33
|
+
def to_s
|
34
|
+
to_i.to_s
|
35
|
+
end
|
36
|
+
alias inspect to_s
|
37
|
+
|
38
|
+
# Move to other
|
39
|
+
def coerce(other)
|
40
|
+
[bytes, other]
|
41
|
+
end
|
42
|
+
|
43
|
+
# Convert to kibi byte
|
44
|
+
def to_kibi_byte
|
45
|
+
to_byte.to_f / divisor
|
46
|
+
end
|
47
|
+
|
48
|
+
# Convert to mebi byte
|
49
|
+
def to_mebi_byte
|
50
|
+
to_kibi_byte.to_f / divisor
|
51
|
+
end
|
52
|
+
|
53
|
+
# Convert to gibi byte
|
54
|
+
def to_gibi_byte
|
55
|
+
to_mebi_byte.to_f / divisor
|
56
|
+
end
|
57
|
+
|
58
|
+
# Compare size with other size
|
59
|
+
def <=>(other)
|
60
|
+
to_i <=> other.to_i
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Aruba
|
2
|
+
module Aruba
|
3
|
+
# Generate script files on command line
|
4
|
+
class ScriptFile
|
5
|
+
private
|
6
|
+
|
7
|
+
attr_reader :path, :content, :interpreter
|
8
|
+
|
9
|
+
public
|
10
|
+
|
11
|
+
def initialize(opts = {})
|
12
|
+
@path = opts[:path]
|
13
|
+
@content = opts[:content]
|
14
|
+
@interpreter = opts[:interpreter]
|
15
|
+
end
|
16
|
+
|
17
|
+
def call
|
18
|
+
Aruba.platform.write_file(path, "#{header}#{content}")
|
19
|
+
Aruba.platform.chmod(0755, path, {})
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def header
|
25
|
+
if script_starts_with_shebang?
|
26
|
+
''
|
27
|
+
elsif interpreter_is_absolute_path?
|
28
|
+
format("#!%s\n", interpreter)
|
29
|
+
elsif interpreter_is_just_the_name_of_shell?
|
30
|
+
format("#!/usr/bin/env %s\n", interpreter)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def interpreter_is_absolute_path?
|
35
|
+
Aruba.platform.absolute_path? interpreter
|
36
|
+
end
|
37
|
+
|
38
|
+
def interpreter_is_just_the_name_of_shell?
|
39
|
+
interpreter =~ /^[-_a-zA-Z.]+$/
|
40
|
+
end
|
41
|
+
|
42
|
+
def script_starts_with_shebang?
|
43
|
+
content.start_with? '#!'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/aruba/hooks.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Aruba
|
2
|
+
module Aruba
|
3
|
+
# Aruba Hooks
|
4
|
+
class Hooks
|
5
|
+
private
|
6
|
+
|
7
|
+
attr_reader :store
|
8
|
+
|
9
|
+
public
|
10
|
+
|
11
|
+
# Create store
|
12
|
+
def initialize
|
13
|
+
@store = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
# Add new hook
|
17
|
+
#
|
18
|
+
# @param [String, Symbol] label
|
19
|
+
# The name of the hook
|
20
|
+
#
|
21
|
+
# @para [Proc] block
|
22
|
+
# The block which should be run for the hook
|
23
|
+
def append(label, block)
|
24
|
+
if store.key?(label.to_sym) && store[label.to_sym].respond_to?(:<<)
|
25
|
+
store[label.to_sym] << block
|
26
|
+
else
|
27
|
+
store[label.to_sym] = []
|
28
|
+
store[label.to_sym] << block
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Run hook
|
33
|
+
#
|
34
|
+
# @param [String, Symbol] label
|
35
|
+
# The name of the hook
|
36
|
+
#
|
37
|
+
# @param [Object] context
|
38
|
+
# The context in which the hook is run
|
39
|
+
#
|
40
|
+
# @param [Array] args
|
41
|
+
# Other arguments
|
42
|
+
def execute(label, context, *args)
|
43
|
+
Array(store[label.to_sym]).each do |block|
|
44
|
+
context.instance_exec(*args, &block)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Check if hook exist
|
49
|
+
#
|
50
|
+
# @param [String, Symbol] label
|
51
|
+
# The name of the hook
|
52
|
+
def exist?(label)
|
53
|
+
store.key? label.to_sym
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|