eac_ruby_utils 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9fbe0a23a64fda20b9d611c418b3162e45a3f94efab0ab60f9e54d82c7c55d17
4
- data.tar.gz: a48d1f5c6dad95964ada07635cc77f54df5dd681ca65bfdb44c7ca280231e665
3
+ metadata.gz: 97f124b1270ea6d57b09ae927a9bd660e433c65a04ac679e35eb8745c1af7f97
4
+ data.tar.gz: 20a01e6cc336bc653266b8672f8ec49bfd2e09284dbae017ed5d5e7a8d22bd46
5
5
  SHA512:
6
- metadata.gz: 0a1552f7e33250db1f919be80116f186f6f8aa24df98a05a37f34189992b7930b1d37eb35a5e2d9948d38dce83b2e303ea32919b1916a8e3a6b7d717d5e50b0e
7
- data.tar.gz: 53adc2c3785559368608d92e17b28d78174653f9c86629f697f46756c4630f6d636943cd814d9a6a09de2ec526dc9dc2e82f7cf80f30d2bb2d785ad363ca450a
6
+ metadata.gz: 8315c63630ea727fef3cea38712b0d33c7971b66e47e6dabe0ff8c5421253de4e520c4ee7f1c8b1946bbcbc66d7652b43c29488d7bfe9b0239d1d508e002f72c
7
+ data.tar.gz: 7fd0d6cfd670dd0c283ebedc165df7d0dd8675f623de67a5a8b86d39ad975e8ad7125497fa87ee60aaa709bf10cb503d49805c126c209c2a2cf73fd834706c7b
@@ -1,12 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'command/extra_options'
4
+
3
5
  module EacRubyUtils
4
6
  module Envs
5
7
  class Command
6
8
  include EacRubyUtils::Console::Speaker
9
+ include EacRubyUtils::Envs::Command::ExtraOptions
7
10
 
8
- def initialize(env, command)
11
+ def initialize(env, command, extra_options = {})
9
12
  @env = env
13
+ @extra_options = extra_options.with_indifferent_access
10
14
  if command.count == 1 && command.first.is_a?(Array)
11
15
  @command = command.first
12
16
  elsif command.is_a?(Array)
@@ -14,26 +18,24 @@ module EacRubyUtils
14
18
  else
15
19
  raise "Invalid argument command: #{command}|#{command.class}"
16
20
  end
17
- @envvars = {}
21
+ end
22
+
23
+ def args
24
+ @command
18
25
  end
19
26
 
20
27
  def append(args)
21
- self.class.new(@env, @command + args)
28
+ duplicate_by_command(@command + args)
22
29
  end
23
30
 
24
31
  def prepend(args)
25
- self.class.new(@env, args + @command)
32
+ duplicate_by_command(args + @command)
26
33
  end
27
34
 
28
35
  def to_s
29
36
  "#{@command} [ENV: #{@env}]"
30
37
  end
31
38
 
32
- def envvar(name, value)
33
- @envvars[name] = value
34
- self
35
- end
36
-
37
39
  def command(options = {})
38
40
  c = @command
39
41
  c = c.map { |x| escape(x) }.join(' ') if c.is_a?(Enumerable)
@@ -45,11 +47,6 @@ module EacRubyUtils
45
47
  )
46
48
  end
47
49
 
48
- def chdir(dir)
49
- @chdir = dir
50
- self
51
- end
52
-
53
50
  def execute!(options = {})
54
51
  er = ExecuteResult.new(execute(options), options)
55
52
  return er.result if er.success?
@@ -67,11 +64,6 @@ module EacRubyUtils
67
64
  r
68
65
  end
69
66
 
70
- def pipe(other_command)
71
- @pipe = other_command
72
- self
73
- end
74
-
75
67
  def system!(options = {})
76
68
  return if system(options)
77
69
 
@@ -86,21 +78,18 @@ module EacRubyUtils
86
78
 
87
79
  private
88
80
 
89
- def debug?
90
- ENV['DEBUG'].to_s.strip != ''
91
- end
81
+ attr_reader :extra_options
92
82
 
93
- def append_envvars(command)
94
- e = @envvars.map { |k, v| "#{Shellwords.escape(k)}=#{Shellwords.escape(v)}" }.join(' ')
95
- e.present? ? "#{e} #{command}" : command
83
+ def duplicate_by_command(new_command)
84
+ self.class.new(@env, new_command, @extra_options)
96
85
  end
97
86
 
98
- def append_pipe(command)
99
- @pipe.present? ? "#{command} | #{@pipe.command}" : command
87
+ def duplicate_by_extra_options(set_extra_options)
88
+ self.class.new(@env, @command, @extra_options.merge(set_extra_options))
100
89
  end
101
90
 
102
- def append_chdir(command)
103
- @chdir.present? ? "(cd '#{@chdir}' ; #{command} )" : command
91
+ def debug?
92
+ ENV['DEBUG'].to_s.strip != ''
104
93
  end
105
94
 
106
95
  def append_command_options(command, options)
@@ -114,8 +103,7 @@ module EacRubyUtils
114
103
  end
115
104
 
116
105
  def escape(arg)
117
- raise "#{arg}|#{arg.class}" unless arg.is_a?(String)
118
-
106
+ arg = arg.to_s
119
107
  m = /^\@ESC_(.+)$/.match(arg)
120
108
  m ? m[1] : Shellwords.escape(arg)
121
109
  end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRubyUtils
4
+ module Envs
5
+ class Command
6
+ module ExtraOptions
7
+ def chdir(dir)
8
+ duplicate_by_extra_options(chdir: dir)
9
+ end
10
+
11
+ def envvar(name, value)
12
+ duplicate_by_extra_options(envvars: envvars.merge(name => value))
13
+ end
14
+
15
+ def pipe(other_command)
16
+ duplicate_by_extra_options(pipe: other_command)
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :extra_options
22
+
23
+ def envvars
24
+ extra_options[:envvars] ||= {}.with_indifferent_access
25
+ end
26
+
27
+ def append_envvars(command)
28
+ e = envvars.map { |k, v| "#{Shellwords.escape(k)}=#{Shellwords.escape(v)}" }.join(' ')
29
+ e.present? ? "#{e} #{command}" : command
30
+ end
31
+
32
+ def append_pipe(command)
33
+ extra_options[:pipe].present? ? "#{command} | #{extra_options[:pipe].command}" : command
34
+ end
35
+
36
+ def append_chdir(command)
37
+ extra_options[:chdir].present? ? "(cd '#{extra_options[:chdir]}' ; #{command} )" : command
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.5.0'
4
+ VERSION = '0.5.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_ruby_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-21 00:00:00.000000000 Z
11
+ date: 2019-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -79,6 +79,7 @@ files:
79
79
  - lib/eac_ruby_utils/envs.rb
80
80
  - lib/eac_ruby_utils/envs/base_env.rb
81
81
  - lib/eac_ruby_utils/envs/command.rb
82
+ - lib/eac_ruby_utils/envs/command/extra_options.rb
82
83
  - lib/eac_ruby_utils/envs/local_env.rb
83
84
  - lib/eac_ruby_utils/envs/process.rb
84
85
  - lib/eac_ruby_utils/envs/ssh_env.rb