aruba 0.11.0.pre → 0.11.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/History.md +21 -1
  4. data/aruba.gemspec +1 -0
  5. data/features/api/command/find_command.feature +83 -0
  6. data/features/api/command/last_command_started.feature +50 -0
  7. data/features/api/command/last_command_stopped.feature +89 -0
  8. data/features/api/command/run.feature +259 -0
  9. data/features/api/command/stop.feature +53 -1
  10. data/features/api/text/replace_variables.feature +1 -1
  11. data/features/getting_started/run_commands.feature +177 -0
  12. data/features/matchers/file/be_existing_executable.feature +87 -0
  13. data/features/{integration/rspec/getting_started.feature → rspec/integration.feature} +31 -0
  14. data/fixtures/getting-started-app/Gemfile +1 -1
  15. data/lib/aruba.rb +0 -19
  16. data/lib/aruba/api.rb +2 -0
  17. data/lib/aruba/api/command.rb +103 -44
  18. data/lib/aruba/api/core.rb +13 -8
  19. data/lib/aruba/api/deprecated.rb +26 -4
  20. data/lib/aruba/api/environment.rb +21 -13
  21. data/lib/aruba/api/filesystem.rb +13 -0
  22. data/lib/aruba/api/rvm.rb +5 -0
  23. data/lib/aruba/api/text.rb +7 -1
  24. data/lib/aruba/aruba_path.rb +6 -0
  25. data/lib/aruba/basic_configuration.rb +35 -3
  26. data/lib/aruba/basic_configuration/option.rb +7 -0
  27. data/lib/aruba/cli.rb +4 -0
  28. data/lib/aruba/command.rb +47 -1
  29. data/lib/aruba/config.rb +15 -2
  30. data/lib/aruba/config_wrapper.rb +49 -8
  31. data/lib/aruba/console.rb +4 -1
  32. data/lib/aruba/console/help.rb +2 -0
  33. data/lib/aruba/contracts/absolute_path.rb +7 -0
  34. data/lib/aruba/contracts/enum.rb +5 -0
  35. data/lib/aruba/contracts/is_power_of_two.rb +9 -2
  36. data/lib/aruba/contracts/relative_path.rb +7 -0
  37. data/lib/aruba/cucumber/command.rb +6 -9
  38. data/lib/aruba/cucumber/file.rb +1 -1
  39. data/lib/aruba/cucumber/hooks.rb +36 -29
  40. data/lib/aruba/errors.rb +16 -1
  41. data/lib/aruba/events.rb +39 -0
  42. data/lib/aruba/extensions/string/strip.rb +1 -0
  43. data/lib/aruba/file_size.rb +11 -0
  44. data/lib/aruba/hooks.rb +2 -0
  45. data/lib/aruba/in_config_wrapper.rb +24 -0
  46. data/lib/aruba/in_process.rb +2 -0
  47. data/lib/aruba/initializer.rb +37 -0
  48. data/lib/aruba/matchers/base/base_matcher.rb +2 -0
  49. data/lib/aruba/matchers/base/object_formatter.rb +4 -0
  50. data/lib/aruba/matchers/collection/all.rb +2 -0
  51. data/lib/aruba/matchers/collection/include_an_object.rb +2 -0
  52. data/lib/aruba/matchers/command/have_exit_status.rb +1 -1
  53. data/lib/aruba/matchers/command/have_finished_in_time.rb +1 -10
  54. data/lib/aruba/matchers/command/have_output.rb +1 -10
  55. data/lib/aruba/matchers/command/have_output_on_stderr.rb +1 -10
  56. data/lib/aruba/matchers/command/have_output_on_stdout.rb +1 -10
  57. data/lib/aruba/matchers/file/be_an_existing_executable.rb +37 -0
  58. data/lib/aruba/platform.rb +4 -0
  59. data/lib/aruba/platforms/announcer.rb +225 -0
  60. data/lib/aruba/platforms/aruba_file_creator.rb +4 -0
  61. data/lib/aruba/platforms/aruba_fixed_size_file_creator.rb +4 -0
  62. data/lib/aruba/{aruba_logger.rb → platforms/aruba_logger.rb} +4 -0
  63. data/lib/aruba/platforms/command_monitor.rb +229 -0
  64. data/lib/aruba/platforms/determine_disk_usage.rb +5 -0
  65. data/lib/aruba/platforms/determine_file_size.rb +9 -0
  66. data/lib/aruba/platforms/disk_usage_calculator.rb +9 -0
  67. data/lib/aruba/platforms/local_environment.rb +12 -0
  68. data/lib/aruba/platforms/simple_table.rb +11 -0
  69. data/lib/aruba/platforms/unix_command_string.rb +3 -0
  70. data/lib/aruba/platforms/unix_environment_variables.rb +3 -0
  71. data/lib/aruba/platforms/unix_platform.rb +20 -2
  72. data/lib/aruba/platforms/unix_which.rb +6 -2
  73. data/lib/aruba/platforms/windows_command_string.rb +7 -0
  74. data/lib/aruba/platforms/windows_environment_variables.rb +2 -0
  75. data/lib/aruba/platforms/windows_platform.rb +3 -0
  76. data/lib/aruba/platforms/windows_which.rb +6 -2
  77. data/lib/aruba/processes/basic_process.rb +20 -5
  78. data/lib/aruba/processes/debug_process.rb +3 -1
  79. data/lib/aruba/processes/in_process.rb +18 -2
  80. data/lib/aruba/processes/spawn_process.rb +14 -13
  81. data/lib/aruba/rspec.rb +34 -23
  82. data/lib/aruba/runtime.rb +65 -6
  83. data/lib/aruba/setup.rb +87 -0
  84. data/lib/aruba/version.rb +1 -1
  85. data/spec/aruba/api_spec.rb +13 -36
  86. data/spec/aruba/{config_wrapper_spec.rb → in_config_wrapper_spec.rb} +1 -1
  87. data/spec/aruba/spawn_process_spec.rb +9 -14
  88. data/spec/support/configs/pry.rb +3 -0
  89. data/spec/support/shared_contexts/aruba.rb +1 -0
  90. metadata +40 -14
  91. data/features/getting_started/supported_programming_languages.feature +0 -89
  92. data/lib/aruba/announcer.rb +0 -219
  93. data/lib/aruba/matchers/rspec.rb +0 -0
  94. data/lib/aruba/process_monitor.rb +0 -201
  95. data/lib/aruba/processes/null_process.rb +0 -26
@@ -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
@@ -1,3 +1,4 @@
1
+ # String
1
2
  class String
2
3
  # Strips indentation in heredocs.
3
4
  #
@@ -1,6 +1,8 @@
1
1
  require 'delegate'
2
2
 
3
+ # Aruba
3
4
  module Aruba
5
+ # File Size
4
6
  class FileSize
5
7
  include Comparable
6
8
 
@@ -10,41 +12,50 @@ module Aruba
10
12
 
11
13
  public
12
14
 
15
+ # Create file size object
13
16
  def initialize(bytes)
14
17
  @bytes = bytes
15
18
  @divisor = 1024
16
19
  end
17
20
 
21
+ # Convert to bytes
18
22
  def to_byte
19
23
  bytes
20
24
  end
21
25
  alias_method :to_i, :to_byte
22
26
 
27
+ # Convert to float
23
28
  def to_f
24
29
  to_i.to_f
25
30
  end
26
31
 
32
+ # Convert to string
27
33
  def to_s
28
34
  to_i.to_s
29
35
  end
30
36
  alias_method :inspect, :to_s
31
37
 
38
+ # Move to other
32
39
  def coerce(other)
33
40
  [bytes, other]
34
41
  end
35
42
 
43
+ # Convert to kibi byte
36
44
  def to_kibi_byte
37
45
  to_byte.to_f / divisor
38
46
  end
39
47
 
48
+ # Convert to mebi byte
40
49
  def to_mebi_byte
41
50
  to_kibi_byte.to_f / divisor
42
51
  end
43
52
 
53
+ # Convert to gibi byte
44
54
  def to_gibi_byte
45
55
  to_mebi_byte.to_f / divisor
46
56
  end
47
57
 
58
+ # Compare size with other size
48
59
  def <=>(other)
49
60
  to_i <=> other.to_i
50
61
  end
data/lib/aruba/hooks.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # Aruba
1
2
  module Aruba
2
3
  # Aruba Hooks
3
4
  class Hooks
@@ -7,6 +8,7 @@ module Aruba
7
8
 
8
9
  public
9
10
 
11
+ # Create store
10
12
  def initialize
11
13
  @store = {}
12
14
  end
@@ -0,0 +1,24 @@
1
+ # Aruba
2
+ module Aruba
3
+ # In config wrapper
4
+ #
5
+ # Used to make the configuration read only if one needs to access an
6
+ # configuration option from with `Aruba::Config`.
7
+ #
8
+ # @private
9
+ class InConfigWrapper
10
+ attr_reader :config
11
+ private :config
12
+
13
+ def initialize(config)
14
+ @config = config.dup
15
+ end
16
+
17
+ def method_missing(name, *args)
18
+ fail ArgumentError, 'Options take no argument' if args.count > 0
19
+ fail UnknownOptionError, %(Option "#{name}" is unknown. Please use only earlier defined options) unless config.key? name
20
+
21
+ config[name]
22
+ end
23
+ end
24
+ end
@@ -1,7 +1,9 @@
1
1
  require 'aruba/processes/in_process'
2
2
  require 'aruba/platform'
3
3
 
4
+ # Aruba
4
5
  module Aruba
6
+ # @deprecated
5
7
  class InProcess < Aruba::Processes::InProcess
6
8
  def initialize(*args)
7
9
  Aruba.platform.deprecated('The use of "Aruba::InProcess" is deprecated. Use "Aruba::Processes::InProcess" instead.')
@@ -1,11 +1,19 @@
1
1
  require 'thor/group'
2
2
  require 'thor/actions'
3
3
 
4
+ # Aruba
4
5
  module Aruba
6
+ # Initializers
7
+ #
8
+ # Initialize project with aruba configuration files
5
9
  module Initializers
10
+ # Common initializer
11
+ #
12
+ # @private
6
13
  class CommonInitializer < Thor::Group
7
14
  include Thor::Actions
8
15
 
16
+ # Add gem to gemfile
9
17
  def add_gem
10
18
  file = 'Gemfile'
11
19
  creator = if File.exist? file
@@ -25,8 +33,15 @@ module Aruba
25
33
  end
26
34
  end
27
35
 
36
+ # Aruba
28
37
  module Aruba
38
+ # Initializers
29
39
  module Initializers
40
+ # Default Initializer
41
+ #
42
+ # This handles invalid values for initializer.
43
+ #
44
+ # @private
30
45
  class FailingInitializer
31
46
  class << self
32
47
  def match?(*)
@@ -41,8 +56,13 @@ module Aruba
41
56
  end
42
57
  end
43
58
 
59
+ # Aruba
44
60
  module Aruba
61
+ # Initializer
45
62
  module Initializers
63
+ # Add aruba + rspec to project
64
+ #
65
+ # @private
46
66
  class RSpecInitializer < Thor::Group
47
67
  include Thor::Actions
48
68
 
@@ -82,8 +102,13 @@ EOS
82
102
  end
83
103
  end
84
104
 
105
+ # Aruba
85
106
  module Aruba
107
+ # Initializer
86
108
  module Initializers
109
+ # Add aruba + aruba to project
110
+ #
111
+ # @private
87
112
  class CucumberInitializer < Thor::Group
88
113
  include Thor::Actions
89
114
 
@@ -102,8 +127,13 @@ EOS
102
127
  end
103
128
  end
104
129
 
130
+ # Aruba
105
131
  module Aruba
132
+ # Initializer
106
133
  module Initializers
134
+ # Add aruba + minitest to project
135
+ #
136
+ # @private
107
137
  class MiniTestInitializer < Thor::Group
108
138
  include Thor::Actions
109
139
 
@@ -155,7 +185,13 @@ EOS
155
185
  end
156
186
  end
157
187
 
188
+ # Aruba
158
189
  module Aruba
190
+ # The whole initializer
191
+ #
192
+ # This one uses the specific initializers to generate the needed files.
193
+ #
194
+ # @private
159
195
  class Initializer
160
196
  private
161
197
 
@@ -171,6 +207,7 @@ module Aruba
171
207
  @initializers << Initializers::FailingInitializer
172
208
  end
173
209
 
210
+ # Create files etc.
174
211
  def call(test_framework)
175
212
  begin
176
213
  initializers.find { |i| i.match? test_framework }.start [], {}
@@ -1,6 +1,8 @@
1
1
  require 'aruba/matchers/base/object_formatter'
2
2
 
3
+ # Aruba
3
4
  module Aruba
5
+ # Matchers
4
6
  module Matchers
5
7
  # Base Matcher
6
8
  class BaseMatcher
@@ -1,7 +1,11 @@
1
+ # Aruba
1
2
  module Aruba
3
+ # Matchers
2
4
  module Matchers
3
5
  # Provide additional output details beyond what `inspect` provides when
4
6
  # printing Time, DateTime, or BigDecimal
7
+ #
8
+ # @private
5
9
  module ObjectFormatter
6
10
  # @api private
7
11
  def self.format(object)
@@ -1,6 +1,8 @@
1
1
  require 'rspec/expectations'
2
2
 
3
+ # Aruba
3
4
  module Aruba
5
+ # Matchers
4
6
  module Matchers
5
7
  include ::RSpec::Matchers
6
8
 
@@ -1,6 +1,8 @@
1
1
  require 'aruba/matchers/base/base_matcher'
2
2
 
3
+ # Aruba
3
4
  module Aruba
5
+ # Matchers
4
6
  module Matchers
5
7
  # @api private
6
8
  # Provides the implementation for `include_an_object`.
@@ -20,7 +20,7 @@ RSpec::Matchers.define :have_exit_status do |expected|
20
20
  match do |actual|
21
21
  @old_actual = actual
22
22
 
23
- @old_actual.stop(announcer) unless @old_actual.stopped?
23
+ @old_actual.stop
24
24
  @actual = actual.exit_status
25
25
 
26
26
  next false unless @old_actual.respond_to? :exit_status
@@ -26,16 +26,7 @@ RSpec::Matchers.define :have_finished_in_time do
26
26
 
27
27
  next false unless @old_actual.respond_to? :timed_out?
28
28
 
29
- @announcer ||= Aruba::Announcer.new(
30
- self,
31
- :stdout => @announce_stdout,
32
- :stderr => @announce_stderr,
33
- :dir => @announce_dir,
34
- :cmd => @announce_cmd,
35
- :env => @announce_env
36
- )
37
-
38
- @old_actual.stop(@announcer) unless @old_actual.stopped?
29
+ @old_actual.stop
39
30
 
40
31
  @old_actual.timed_out? == false
41
32
  end
@@ -19,16 +19,7 @@ RSpec::Matchers.define :have_output do |expected|
19
19
 
20
20
  next false unless @old_actual.respond_to? :output
21
21
 
22
- @announcer ||= Aruba::Announcer.new(
23
- self,
24
- :stdout => @announce_stdout,
25
- :stderr => @announce_stderr,
26
- :dir => @announce_dir,
27
- :cmd => @announce_cmd,
28
- :env => @announce_env
29
- )
30
-
31
- @old_actual.stop(@announcer)
22
+ @old_actual.stop
32
23
 
33
24
  @actual = sanitize_text(actual.output)
34
25
 
@@ -19,16 +19,7 @@ RSpec::Matchers.define :have_output_on_stderr do |expected|
19
19
 
20
20
  next false unless @old_actual.respond_to? :stderr
21
21
 
22
- @announcer ||= Aruba::Announcer.new(
23
- self,
24
- :stdout => @announce_stdout,
25
- :stderr => @announce_stderr,
26
- :dir => @announce_dir,
27
- :cmd => @announce_cmd,
28
- :env => @announce_env
29
- )
30
-
31
- @old_actual.stop(@announcer) unless @old_actual.stopped?
22
+ @old_actual.stop
32
23
 
33
24
  @actual = sanitize_text(actual.stderr)
34
25
 
@@ -19,16 +19,7 @@ RSpec::Matchers.define :have_output_on_stdout do |expected|
19
19
 
20
20
  next false unless @old_actual.respond_to? :stdout
21
21
 
22
- @announcer ||= Aruba::Announcer.new(
23
- self,
24
- :stdout => @announce_stdout,
25
- :stderr => @announce_stderr,
26
- :dir => @announce_dir,
27
- :cmd => @announce_cmd,
28
- :env => @announce_env
29
- )
30
-
31
- @old_actual.stop(@announcer) unless @old_actual.stopped?
22
+ @old_actual.stop
32
23
 
33
24
  @actual = sanitize_text(actual.stdout)
34
25
 
@@ -0,0 +1,37 @@
1
+ require 'rspec/expectations/version'
2
+ require 'shellwords'
3
+
4
+ # @!method be_an_existing_executable
5
+ # This matchers checks if <file> exists in filesystem
6
+ #
7
+ # @return [TrueClass, FalseClass] The result
8
+ #
9
+ # false:
10
+ # * if file does not exist
11
+ # true:
12
+ # * if file exists
13
+ #
14
+ # @example Use matcher
15
+ #
16
+ # RSpec.describe do
17
+ # it { expect(file1).to be_an_existing_executable }
18
+ # end
19
+ RSpec::Matchers.define :be_an_existing_executable do |_|
20
+ match do |actual|
21
+ @actual = Shellwords.split(actual.commandline).first if actual.respond_to? :commandline
22
+
23
+ executable?(@actual)
24
+ end
25
+
26
+ failure_message do |actual|
27
+ format("expected that executable \"%s\" exists", actual)
28
+ end
29
+
30
+ failure_message_when_negated do |actual|
31
+ format("expected that executable \"%s\" does not exist", actual)
32
+ end
33
+ end
34
+
35
+ if RSpec::Expectations::Version::STRING >= '3.0'
36
+ RSpec::Matchers.alias_matcher :an_existing_executable, :be_an_existing_executable
37
+ end
@@ -2,14 +2,18 @@ require 'thread'
2
2
  require 'aruba/platforms/unix_platform'
3
3
  require 'aruba/platforms/windows_platform'
4
4
 
5
+ # Aruba
5
6
  module Aruba
6
7
  PLATFORM_MUTEX = Mutex.new
7
8
  end
8
9
 
10
+ # Aruba
9
11
  module Aruba
12
+ # Platform
10
13
  Platform = [Platforms::WindowsPlatform, Platforms::UnixPlatform].find(&:match?)
11
14
  end
12
15
 
16
+ # Aruba
13
17
  module Aruba
14
18
  PLATFORM_MUTEX.synchronize do
15
19
  @platform = Platform.new
@@ -0,0 +1,225 @@
1
+ require 'shellwords'
2
+
3
+ # Aruba
4
+ module Aruba
5
+ # Platforms
6
+ module Platforms
7
+ # Announcer
8
+ #
9
+ # @private
10
+ #
11
+ # @example Activate your you own channel in cucumber
12
+ #
13
+ # Before('@announce-my-channel') do
14
+ # aruba.announcer.activate :my_channel
15
+ # end
16
+ #
17
+ # @example Activate your you own channel in rspec > 3
18
+ #
19
+ # before do
20
+ # current_example = context.example
21
+ # aruba.announcer.activate :my_channel if current_example.metadata[:announce_my_channel]
22
+ # end
23
+ #
24
+ # Aruba.announcer.announce(:my_channel, 'my message')
25
+ #
26
+ class Announcer
27
+ # Dev null
28
+ class NullAnnouncer
29
+ def announce(*)
30
+ nil
31
+ end
32
+
33
+ def mode?(*)
34
+ true
35
+ end
36
+ end
37
+
38
+ # Announcer using Kernel.puts
39
+ class KernelPutsAnnouncer
40
+ def announce(message)
41
+ Kernel.puts message
42
+ end
43
+
44
+ def mode?(m)
45
+ :kernel_puts == m
46
+ end
47
+ end
48
+
49
+ # Announcer using Main#puts
50
+ class PutsAnnouncer
51
+ def announce(message)
52
+ Kernel.puts message
53
+ end
54
+
55
+ def mode?(m)
56
+ :puts == m
57
+ end
58
+ end
59
+
60
+ private
61
+
62
+ attr_reader :announcers, :default_announcer, :announcer, :channels, :output_formats
63
+
64
+ public
65
+
66
+ def initialize(*args)
67
+ @announcers = []
68
+ @announcers << PutsAnnouncer.new
69
+ @announcers << KernelPutsAnnouncer.new
70
+ @announcers << NullAnnouncer.new
71
+
72
+ @default_announcer = @announcers.last
73
+ @announcer = @announcers.first
74
+ @channels = {}
75
+ @output_formats = {}
76
+
77
+ @options = args[1] || {}
78
+
79
+ after_init
80
+ end
81
+
82
+ private
83
+
84
+ # rubocop:disable Metrics/MethodLength
85
+ def after_init
86
+ output_format :changed_configuration, proc { |n, v| format('# %s = %s', n, v) }
87
+ output_format :changed_environment, proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) }
88
+ output_format :command, '$ %s'
89
+ output_format :directory, '$ cd %s'
90
+ output_format :environment, proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) }
91
+ output_format :full_environment, proc { |h| Aruba.platform.simple_table(h) }
92
+ output_format :modified_environment, proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) }
93
+ output_format :stderr, "<<-STDERR\n%s\nSTDERR"
94
+ output_format :stdout, "<<-STDOUT\n%s\nSTDOUT"
95
+ output_format :stop_signal, proc { |p, s| format('Command will be stopped with `kill -%s %s`', s, p) }
96
+ output_format :timeout, '# %s-timeout: %s seconds'
97
+ output_format :wait_time, '# %s: %s seconds'
98
+
99
+ # rubocop:disable Metrics/LineLength
100
+ if @options[:stdout]
101
+ warn('The use of "@announce_stdout-instance" variable and "options[:stdout] = true" for Announcer.new is deprecated. Please use "announcer.activate(:stdout)" instead.')
102
+ activate :stdout
103
+ end
104
+ if @options[:stderr]
105
+ warn('The use of "@announce_stderr-instance" variable and "options[:stderr] = true" for Announcer.new is deprecated. Please use "announcer.activate(:stderr)" instead.')
106
+ activate :stderr
107
+ end
108
+ if @options[:dir]
109
+ warn('The use of "@announce_dir-instance" variable and "options[:dir] = true" for Announcer.new is deprecated. Please use "announcer.activate(:directory)" instead.')
110
+ activate :directory
111
+ end
112
+ if @options[:cmd]
113
+ warn('The use of "@announce_cmd-instance" variable and "options[:cmd] = true" for Announcer.new is deprecated. Please use "announcer.activate(:command)" instead.')
114
+ activate :command
115
+ end
116
+ if @options[:env]
117
+ warn('The use of "@announce_env-instance" variable and "options[:env] = true" for Announcer.new is deprecated. Please use "announcer.activate(:modified_environment)" instead.')
118
+ activate :modified_enviroment
119
+ end
120
+ # rubocop:enable Metrics/LineLength
121
+ end
122
+ # rubocop:enable Metrics/MethodLength
123
+
124
+ def output_format(channel, string = '%s', &block)
125
+ if block_given?
126
+ output_formats[channel.to_sym] = block
127
+ elsif string.is_a?(Proc)
128
+ output_formats[channel.to_sym] = string
129
+ else
130
+ output_formats[channel.to_sym] = proc { |*args| format(string, *args) }
131
+ end
132
+ end
133
+
134
+ public
135
+
136
+ # Reset announcer
137
+ def reset
138
+ @default_announcer = @announcers.last
139
+ @announcer = @announcers.first
140
+ end
141
+
142
+ # Change mode of announcer
143
+ #
144
+ # @param [Symbol] m
145
+ # The mode to set
146
+ def mode=(m)
147
+ @announcer = @announcers.find { |a| f.mode? m.to_sym }
148
+
149
+ self
150
+ end
151
+
152
+ # Check if channel is activated
153
+ #
154
+ # @param [Symbol] channel
155
+ # The name of the channel to check
156
+ def activated?(channel)
157
+ channels[channel.to_sym] == true
158
+ end
159
+
160
+ # Activate a channel
161
+ #
162
+ # @param [Symbol] channel
163
+ # The name of the channel to activate
164
+ def activate(channel)
165
+ channels[channel.to_sym] = true
166
+
167
+ self
168
+ end
169
+
170
+ # Announce information to channel
171
+ #
172
+ # @param [Symbol] channel
173
+ # The name of the channel to check
174
+ #
175
+ # @param [Array] args
176
+ # Arguments
177
+ def announce(channel, *args)
178
+ channel = channel.to_sym
179
+
180
+ the_output_format = if output_formats.key? channel
181
+ output_formats[channel]
182
+ else
183
+ proc { |v| format('%s', v) }
184
+ end
185
+
186
+ message = the_output_format.call(*args)
187
+
188
+ announcer.announce(message) if channels[channel]
189
+
190
+ default_announcer.announce message
191
+ end
192
+
193
+ # @deprecated
194
+ def stdout(content)
195
+ warn('The announcer now has a new api to activate channels. Please use this one: announce(:stdout, message)')
196
+ announce :stdout, content
197
+ end
198
+
199
+ # @deprecated
200
+ def stderr(content)
201
+ warn('The announcer now has a new api to activate channels. Please use this one: announce(:stderr, message)')
202
+ announce :stderr, content
203
+ end
204
+
205
+ # @deprecated
206
+ def dir(dir)
207
+ warn('The announcer now has a new api to activate channels. Please use this one announce(:directory, message)')
208
+ announce :directory, dir
209
+ end
210
+
211
+ # @deprecated
212
+ def cmd(cmd)
213
+ warn('The announcer now has a new api to activate channels. Please use this one announce(:command, message)')
214
+ announce :command, cmd
215
+ end
216
+
217
+ # @deprecated
218
+ def env(name, value)
219
+ warn('The announcer now has a new api to activate channels. Please use this one: announce(:changed_environment, key, value)')
220
+
221
+ announce :changed_environment, name, value
222
+ end
223
+ end
224
+ end
225
+ end