avm-tools 0.114.0 → 0.115.0
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 +4 -4
- data/lib/avm/launcher/git/publish_base.rb +2 -0
- data/lib/avm/tools/version.rb +1 -1
- data/sub/avm/lib/avm/instances/base/auto_values/database.rb +2 -2
- data/sub/avm/lib/avm/instances/entry_keys.rb +2 -1
- data/{lib → sub/avm/lib}/avm/launcher/errors/base.rb +0 -0
- data/{lib → sub/avm/lib}/avm/launcher/errors/non_project.rb +0 -0
- data/{lib → sub/avm/lib}/avm/launcher/paths/real.rb +0 -0
- data/{lib → sub/avm/lib}/avm/launcher/publish/check_result.rb +0 -0
- data/sub/avm/lib/avm/self/instance.rb +0 -1
- data/sub/avm/lib/avm/sources/base/instance.rb +28 -0
- data/sub/avm/lib/avm/version.rb +1 -1
- data/sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0/instance/assert.rb +77 -0
- data/sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0/instance.rb +23 -12
- data/sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0/version.rb +1 -1
- data/sub/avm-eac_rails_base0/lib/avm/eac_rails_base0/deploy.rb +1 -1
- data/sub/avm-eac_rails_base0/lib/avm/eac_rails_base0/version.rb +1 -1
- data/sub/avm-eac_redmine_base0/avm-eac_redmine_base0.gemspec +1 -0
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/data_unit.rb +6 -10
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instance.rb +20 -0
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/rest_api.rb +11 -0
- data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/version.rb +1 -1
- data/sub/avm-eac_redmine_base0/template/avm/eac_redmine_base0/deploy/config/install.sh.template +3 -3
- data/sub/avm-files/lib/avm/files/formatter/formats/generic_plain.rb +2 -2
- data/sub/avm-files/lib/avm/files/version.rb +1 -1
- data/sub/eac_cli/lib/eac_cli/runner/context.rb +4 -0
- data/sub/eac_cli/lib/eac_cli/runner/instance_methods.rb +10 -0
- data/sub/eac_cli/lib/eac_cli/speaker.rb +1 -2
- data/sub/eac_cli/lib/eac_cli/version.rb +1 -1
- data/sub/eac_fs/lib/eac_fs/cached_download.rb +2 -2
- data/sub/eac_fs/lib/eac_fs/patches/object/fs_cache.rb +6 -1
- data/sub/eac_fs/lib/eac_fs/version.rb +1 -1
- data/sub/eac_rest/Gemfile +5 -0
- data/sub/eac_rest/eac_rest.gemspec +18 -0
- data/sub/eac_rest/lib/eac_rest/api.rb +39 -0
- data/sub/eac_rest/lib/eac_rest/entity.rb +16 -0
- data/sub/eac_rest/lib/eac_rest/request.rb +74 -0
- data/sub/eac_rest/lib/eac_rest/response.rb +72 -0
- data/sub/eac_rest/lib/eac_rest/version.rb +5 -0
- data/sub/eac_rest/lib/eac_rest.rb +7 -0
- data/sub/eac_rest/spec/rubocop_spec.rb +3 -0
- data/sub/eac_rest/spec/spec_helper.rb +4 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/bit.rb +46 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/bit_array.rb +81 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/byte.rb +105 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/byte_array.rb +36 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/executable.rb +21 -3
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/envs/process.rb +12 -4
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/asserts.rb +11 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/to_uri.rb +15 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname/basename_noext.rb +10 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname/reqdir_glob.rb +13 -0
- data/sub/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/bit_array_spec.rb +22 -0
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/byte_spec.rb +54 -0
- data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/pathname/basename_noext_spec.rb +26 -0
- metadata +35 -12
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'curb'
|
4
|
+
require 'eac_rest/response'
|
5
|
+
require 'eac_ruby_utils/core_ext'
|
6
|
+
require 'ostruct'
|
7
|
+
|
8
|
+
module EacRest
|
9
|
+
class Request
|
10
|
+
COMMON_MODIFIERS = %w[auth body_data verb].freeze
|
11
|
+
HASH_MODIFIERS = %w[header].freeze
|
12
|
+
MODIFIERS = COMMON_MODIFIERS + HASH_MODIFIERS.map(&:pluralize)
|
13
|
+
|
14
|
+
enable_immutable
|
15
|
+
immutable_accessor(*COMMON_MODIFIERS, type: :common)
|
16
|
+
immutable_accessor(*HASH_MODIFIERS, type: :hash)
|
17
|
+
|
18
|
+
enable_listable
|
19
|
+
lists.add_symbol :verb, :get, :delete, :options, :post, :put
|
20
|
+
|
21
|
+
common_constructor :url, :body_data_proc, default: [nil]
|
22
|
+
|
23
|
+
def autenticate(username, password)
|
24
|
+
auth(::OpenStruct.new(username: username, password: password))
|
25
|
+
end
|
26
|
+
|
27
|
+
def immutable_constructor_args
|
28
|
+
[url, body_data_proc]
|
29
|
+
end
|
30
|
+
|
31
|
+
def response
|
32
|
+
::EacRest::Response.new(build_curl, body_data_proc)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def build_curl
|
38
|
+
r = ::Curl::Easy.new(url)
|
39
|
+
MODIFIERS.each { |suffix| send("build_curl_#{suffix}", r) }
|
40
|
+
r
|
41
|
+
end
|
42
|
+
|
43
|
+
def build_curl_auth(curl)
|
44
|
+
auth.if_present do |a|
|
45
|
+
curl.http_auth_types = :basic
|
46
|
+
curl.username = a.username
|
47
|
+
curl.password = a.password
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def build_curl_body_data(curl)
|
52
|
+
www_form_body_data_encoded.if_present { |v| curl.post_body = v }
|
53
|
+
end
|
54
|
+
|
55
|
+
def build_curl_headers(curl)
|
56
|
+
curl.headers.merge!(headers)
|
57
|
+
end
|
58
|
+
|
59
|
+
def build_curl_verb(curl)
|
60
|
+
curl.set(
|
61
|
+
:customrequest,
|
62
|
+
verb.if_present(VERB_GET) { |v| self.class.lists.verb.value_validate!(v) }.to_s.upcase
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
def www_form_body_data_encoded
|
67
|
+
body_data.if_present do |v|
|
68
|
+
v = v.map { |k, vv| [k, vv] } if v.is_a?(::Hash)
|
69
|
+
v = URI.encode_www_form(v) if v.is_a?(::Array)
|
70
|
+
v.to_s
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/hash/conversions'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
module EacRest
|
8
|
+
class Response < ::StandardError
|
9
|
+
common_constructor :curl, :body_data_proc
|
10
|
+
|
11
|
+
def body_data
|
12
|
+
r = performed_curl.headers['Accept'].if_present(body_str) do |v|
|
13
|
+
method_name = "body_data_from_#{v.parameterize.underscore}"
|
14
|
+
respond_to?(method_name) ? send(method_name) : body_str
|
15
|
+
end
|
16
|
+
r = body_data_proc.call(r) if body_data_proc.present?
|
17
|
+
r
|
18
|
+
end
|
19
|
+
|
20
|
+
def body_data_or_raise
|
21
|
+
raise_unless_200
|
22
|
+
|
23
|
+
body_data
|
24
|
+
end
|
25
|
+
|
26
|
+
delegate :body_str, :headers, to: :performed_curl
|
27
|
+
|
28
|
+
def body_str_or_raise
|
29
|
+
raise_unless_200
|
30
|
+
|
31
|
+
body_str
|
32
|
+
end
|
33
|
+
|
34
|
+
def raise_unless_200
|
35
|
+
return nil if status == 200
|
36
|
+
|
37
|
+
raise self
|
38
|
+
end
|
39
|
+
|
40
|
+
def status
|
41
|
+
performed_curl.status.to_i
|
42
|
+
end
|
43
|
+
|
44
|
+
delegate :url, to: :curl
|
45
|
+
|
46
|
+
def to_s
|
47
|
+
"URL: #{url}\nStatus: #{status}\nBody:\n\n#{body_str}"
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def body_data_from_application_json
|
53
|
+
::JSON.parse(body_str)
|
54
|
+
end
|
55
|
+
|
56
|
+
def body_data_from_application_xml
|
57
|
+
Hash.from_xml(body_str)
|
58
|
+
end
|
59
|
+
|
60
|
+
def perform
|
61
|
+
@perform ||= begin
|
62
|
+
curl.perform || raise("CURL perform failed for #{url}")
|
63
|
+
true
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def performed_curl
|
68
|
+
perform
|
69
|
+
curl
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/patches/module/compare_by'
|
4
|
+
|
5
|
+
module EacRubyUtils
|
6
|
+
class Bit
|
7
|
+
VALID_VALUES = [0, 1].freeze
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def assert(obj)
|
11
|
+
return obj if obj.is_a?(self)
|
12
|
+
|
13
|
+
new(obj.to_i)
|
14
|
+
end
|
15
|
+
|
16
|
+
def valid_integer?(value)
|
17
|
+
value.is_a?(::Integer) && VALID_VALUES.include?(value)
|
18
|
+
end
|
19
|
+
|
20
|
+
def validate_integer(value)
|
21
|
+
return value if valid_integer?(value)
|
22
|
+
|
23
|
+
raise(::ArgumentError, "Invalid bit value: #{value} (Valid: #{VALID_VALUES})")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_reader :value
|
28
|
+
compare_by :value
|
29
|
+
delegate :to_s, :zero?, to: :value
|
30
|
+
|
31
|
+
# @param value [Integer]
|
32
|
+
def initialize(value)
|
33
|
+
@value = self.class.validate_integer(value)
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [Boolean]
|
37
|
+
def one?
|
38
|
+
!zero?
|
39
|
+
end
|
40
|
+
|
41
|
+
# @return [Integer]
|
42
|
+
def to_i
|
43
|
+
value
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/bit'
|
4
|
+
require 'eac_ruby_utils/byte'
|
5
|
+
require 'eac_ruby_utils/byte_array'
|
6
|
+
require 'eac_ruby_utils/patches/module/compare_by'
|
7
|
+
|
8
|
+
module EacRubyUtils
|
9
|
+
class BitArray
|
10
|
+
class << self
|
11
|
+
def assert(obj)
|
12
|
+
return obj if obj.is_a?(self)
|
13
|
+
return new(obj) if obj.is_a?(::Enumerable)
|
14
|
+
|
15
|
+
raise "Could not convert #{obj} to #{self}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
delegate :each, :each_with_index, :to_a, :size, :count, :length, :[], :fetch, to: :values_array
|
20
|
+
compare_by :values_array
|
21
|
+
|
22
|
+
def initialize(values = [])
|
23
|
+
values.each { |value| push(value) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def <<(value)
|
27
|
+
push(value)
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [EacRubyUtils::BitArray] +self+.
|
31
|
+
def push_array(other_bit_array)
|
32
|
+
values_array.push(*other_bit_array.to_a)
|
33
|
+
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
# @param value [EacRubyUtils::Bit]
|
38
|
+
# @return [EacRubyUtils::Bit]
|
39
|
+
def push(value)
|
40
|
+
values_array.push(::EacRubyUtils::Bit.assert(value))
|
41
|
+
end
|
42
|
+
|
43
|
+
# @return [EacRubyUtils::BitArray]
|
44
|
+
def reverse
|
45
|
+
self.class.new(values_array.reverse)
|
46
|
+
end
|
47
|
+
|
48
|
+
# @param big_endian [Boolean]
|
49
|
+
# @return [EacRubyUtils::ByteArray]
|
50
|
+
def to_byte_array(big_endian = false)
|
51
|
+
unless count.modulo(::EacRubyUtils::Byte::BIT_COUNT).zero?
|
52
|
+
raise 'Bits returned is not multile of 8'
|
53
|
+
end
|
54
|
+
|
55
|
+
byte_bits_enumerator.each_with_object(::EacRubyUtils::ByteArray.new) do |e, a|
|
56
|
+
a << ::EacRubyUtils::Byte.from_bit_array(e, big_endian)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# @return [Array<Integer>]
|
61
|
+
def to_int_array
|
62
|
+
values_array.map(&:to_i)
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def byte_bits_enumerator
|
68
|
+
::Enumerator.new do |y|
|
69
|
+
offset = 0
|
70
|
+
while offset < values_array.count
|
71
|
+
y.yield(values_array.slice(offset, ::EacRubyUtils::Byte::BIT_COUNT))
|
72
|
+
offset += ::EacRubyUtils::Byte::BIT_COUNT
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def values_array
|
78
|
+
@values_array ||= []
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/bit'
|
4
|
+
require 'eac_ruby_utils/bit_array'
|
5
|
+
require 'eac_ruby_utils/patches/module/compare_by'
|
6
|
+
|
7
|
+
module EacRubyUtils
|
8
|
+
class Byte
|
9
|
+
ASSEMBLY_HEXADECIMAL_PREFIX = '$'
|
10
|
+
BIT_COUNT = 8
|
11
|
+
BIT_INDEX_RANGE = (0..7).freeze
|
12
|
+
VALUE_RANGE = (0..255).freeze
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def assert(obj)
|
16
|
+
return obj if obj.is_a?(self)
|
17
|
+
|
18
|
+
new(obj.to_i)
|
19
|
+
end
|
20
|
+
|
21
|
+
def from_bit_array(bit_array, big_endian = false)
|
22
|
+
bit_array = ::EacRubyUtils::BitArray.assert(bit_array)
|
23
|
+
raise ::ArgumentError, "Wrong bit array size: #{bit_array.size}" if
|
24
|
+
bit_array.size != BIT_COUNT
|
25
|
+
|
26
|
+
bit_array = bit_array.reverse if big_endian
|
27
|
+
bit_array.each_with_index.inject(new(0)) do |a, e|
|
28
|
+
a.bit_set(e[1], e[0])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def valid_bit_index?(value)
|
33
|
+
value.is_a?(::Integer) && BIT_INDEX_RANGE.include?(value)
|
34
|
+
end
|
35
|
+
|
36
|
+
def validate_bit_index(value)
|
37
|
+
return value if valid_bit_index?(value)
|
38
|
+
|
39
|
+
raise(::ArgumentError, "Invalid bit index: #{value} (Range: #{BIT_INDEX_RANGE})")
|
40
|
+
end
|
41
|
+
|
42
|
+
def valid_value?(value)
|
43
|
+
value.is_a?(::Integer) && VALUE_RANGE.include?(value)
|
44
|
+
end
|
45
|
+
|
46
|
+
def validate_value(value)
|
47
|
+
return value if valid_value?(value)
|
48
|
+
|
49
|
+
raise(::ArgumentError, "Invalid byte value: #{value} (Range: #{VALUE_RANGE})")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
attr_reader :value
|
54
|
+
compare_by :value
|
55
|
+
|
56
|
+
def initialize(value)
|
57
|
+
self.value = value
|
58
|
+
end
|
59
|
+
|
60
|
+
# @param bit_index [Integer]
|
61
|
+
# @return [EacRubyUtils::Bit]
|
62
|
+
def [](bit_index)
|
63
|
+
bit_get(bit_index)
|
64
|
+
end
|
65
|
+
|
66
|
+
# @param bit_index [Integer]
|
67
|
+
# @return [EacRubyUtils::Bit]
|
68
|
+
def bit_get(bit_index)
|
69
|
+
self.class.validate_bit_index(bit_index)
|
70
|
+
|
71
|
+
::EacRubyUtils::Bit.new((value & (1 << bit_index)) >> bit_index)
|
72
|
+
end
|
73
|
+
|
74
|
+
def bit_set(bit_index, bit_value)
|
75
|
+
self.class.validate_bit_index(bit_index)
|
76
|
+
bit = ::EacRubyUtils::Bit.assert(bit_value)
|
77
|
+
mask = (1 << bit_index)
|
78
|
+
self.class.new(bit.zero? ? value & ~mask : value | mask)
|
79
|
+
end
|
80
|
+
|
81
|
+
# @return [EacRubyUtils::BitArray]
|
82
|
+
def to_bit_array(range = BIT_INDEX_RANGE)
|
83
|
+
::EacRubyUtils::BitArray.new(range.map { |bit_index| self[bit_index] })
|
84
|
+
end
|
85
|
+
|
86
|
+
# @return [Integer]
|
87
|
+
def to_i
|
88
|
+
value
|
89
|
+
end
|
90
|
+
|
91
|
+
# @return [String]
|
92
|
+
def to_asm_hex
|
93
|
+
ASSEMBLY_HEXADECIMAL_PREFIX + to_hex
|
94
|
+
end
|
95
|
+
|
96
|
+
# @return [String]
|
97
|
+
def to_hex
|
98
|
+
value.to_s(16).upcase.rjust(2, '0')
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
|
103
|
+
attr_writer :value
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/byte'
|
4
|
+
require 'eac_ruby_utils/patches/module/compare_by'
|
5
|
+
|
6
|
+
module EacRubyUtils
|
7
|
+
class ByteArray
|
8
|
+
delegate :to_a, :size, :count, :length, :[], :fetch, :map, to: :values_array
|
9
|
+
compare_by :values_array
|
10
|
+
|
11
|
+
def initialize(values = [])
|
12
|
+
values.each { |value| push(value) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def <<(value)
|
16
|
+
push(value)
|
17
|
+
end
|
18
|
+
|
19
|
+
# @param value [EacRubyUtils::Byte]
|
20
|
+
# @return [EacRubyUtils::Byte]
|
21
|
+
def push(value)
|
22
|
+
values_array.push(::EacRubyUtils::Byte.assert(value))
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [Array<Integer>]
|
26
|
+
def to_int_array
|
27
|
+
values_array.map(&:to_i)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def values_array
|
33
|
+
@values_array ||= []
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,18 +1,34 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'eac_ruby_utils/listable'
|
3
4
|
require 'eac_ruby_utils/simple_cache'
|
4
5
|
|
5
6
|
module EacRubyUtils
|
6
7
|
module Envs
|
7
8
|
class Executable
|
9
|
+
include ::EacRubyUtils::Listable
|
8
10
|
include ::EacRubyUtils::SimpleCache
|
9
11
|
|
10
|
-
|
12
|
+
lists.add_symbol :option, :check_args, :auto_validate
|
13
|
+
|
14
|
+
DEFAULT_AUTO_VALIDATE = true
|
15
|
+
|
16
|
+
attr_reader :env, :name, :options
|
11
17
|
|
12
18
|
def initialize(env, name, *check_args)
|
13
19
|
@env = env
|
14
20
|
@name = name
|
15
|
-
|
21
|
+
self.options = self.class.lists.option.hash_keys_validate!(check_args.extract_options!)
|
22
|
+
options[OPTION_CHECK_ARGS] = check_args unless options.key?(OPTION_CHECK_ARGS)
|
23
|
+
options.freeze
|
24
|
+
end
|
25
|
+
|
26
|
+
def auto_validate?
|
27
|
+
options.key?(OPTION_AUTO_VALIDATE) ? options[OPTION_AUTO_VALIDATE] : DEFAULT_AUTO_VALIDATE
|
28
|
+
end
|
29
|
+
|
30
|
+
def check_args
|
31
|
+
options[OPTION_CHECK_ARGS]
|
16
32
|
end
|
17
33
|
|
18
34
|
def exist?
|
@@ -32,7 +48,7 @@ module EacRubyUtils
|
|
32
48
|
end
|
33
49
|
|
34
50
|
def command(*command_args)
|
35
|
-
validate!
|
51
|
+
validate! if auto_validate?
|
36
52
|
env.command(*executable_args, *command_args)
|
37
53
|
end
|
38
54
|
|
@@ -50,6 +66,8 @@ module EacRubyUtils
|
|
50
66
|
|
51
67
|
private
|
52
68
|
|
69
|
+
attr_writer :options
|
70
|
+
|
53
71
|
def exist_uncached
|
54
72
|
env.command(*executable_args, *check_args).execute!
|
55
73
|
true
|
@@ -5,15 +5,23 @@ require 'open3'
|
|
5
5
|
module EacRubyUtils
|
6
6
|
module Envs
|
7
7
|
class Process
|
8
|
+
EXIT_CODE_KEY = :exit_code
|
9
|
+
ERR_KEY = :stderr
|
10
|
+
OUT_KEY = :stdout
|
11
|
+
|
8
12
|
def initialize(command)
|
9
|
-
|
10
|
-
|
11
|
-
|
13
|
+
self.data = { command: command }
|
14
|
+
data[OUT_KEY], data[ERR_KEY], data[EXIT_CODE_KEY] = Open3.capture3(command)
|
15
|
+
data[EXIT_CODE_KEY] = data[EXIT_CODE_KEY].to_i
|
12
16
|
end
|
13
17
|
|
14
18
|
def to_h
|
15
|
-
|
19
|
+
data.dup
|
16
20
|
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_accessor :data
|
17
25
|
end
|
18
26
|
end
|
19
27
|
end
|
@@ -11,4 +11,15 @@ class Object
|
|
11
11
|
"Argument \"#{argument_name}\" is not a #{klass}" \
|
12
12
|
"(Actual class: #{self.class}, actual value: #{self})"
|
13
13
|
end
|
14
|
+
|
15
|
+
# Raises a ArgumentError if +self.count+ is not equal to +count+.
|
16
|
+
#
|
17
|
+
# @return +self+
|
18
|
+
def assert_count(count, argument_name = 'unknown_argument_name')
|
19
|
+
return self if self.count == count
|
20
|
+
|
21
|
+
raise ::ArgumentError,
|
22
|
+
"Argument \"#{argument_name}\" has wrong elements count" \
|
23
|
+
"(Actual: #{self.count}, Required: #{count})"
|
24
|
+
end
|
14
25
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/object/blank'
|
4
|
+
require 'addressable/uri'
|
5
|
+
|
6
|
+
class Object
|
7
|
+
# Convert +self+ to String and then to Addressable::URI. Return nil if +self+ is +blank?+.
|
8
|
+
#
|
9
|
+
# @return [Addressable::URI]
|
10
|
+
def to_uri
|
11
|
+
return self if is_a?(::Addressable::URI)
|
12
|
+
|
13
|
+
to_s.blank? ? nil : ::Addressable::URI.parse(to_s)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
class Pathname
|
6
|
+
# A .glob that raises a ::RuntimeError if +self+ is not a directory.
|
7
|
+
# @return [Pathname]
|
8
|
+
def reqdir_glob(*args)
|
9
|
+
raise ::RuntimeError, "\"#{self}\" is not a directory" unless directory?
|
10
|
+
|
11
|
+
glob(*args)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/bit_array'
|
4
|
+
|
5
|
+
RSpec.describe ::EacRubyUtils::BitArray do
|
6
|
+
describe '#to_byte_array' do
|
7
|
+
let(:instance) { described_class.new([0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1]) }
|
8
|
+
|
9
|
+
{
|
10
|
+
false => [0xF0, 0xDC],
|
11
|
+
true => [0x0F, 0x3B]
|
12
|
+
}.each do |big_endian, expected_bytes|
|
13
|
+
context "when big-endian is #{big_endian}" do
|
14
|
+
let(:expected_value) { ::EacRubyUtils::ByteArray.new(expected_bytes) }
|
15
|
+
|
16
|
+
it do
|
17
|
+
expect(instance.to_byte_array(big_endian)).to eq(expected_value)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/byte'
|
4
|
+
|
5
|
+
RSpec.describe ::EacRubyUtils::Byte do
|
6
|
+
describe '#[]' do
|
7
|
+
let(:instance) { described_class.new(0xDC) }
|
8
|
+
|
9
|
+
[0, 0, 1, 1, 1, 0, 1, 1].each_with_index do |bit_value, bit_index|
|
10
|
+
context "when bit index is #{bit_index}" do
|
11
|
+
it { expect(instance[bit_index].value).to eq(bit_value) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#bit_set' do
|
17
|
+
let(:instance) { described_class.new(0b11011100) }
|
18
|
+
|
19
|
+
{
|
20
|
+
0 => [0b11011100, 0b11011100, 0b11011000, 0b11010100,
|
21
|
+
0b11001100, 0b11011100, 0b10011100, 0b01011100],
|
22
|
+
1 => [0b11011101, 0b11011110, 0b11011100, 0b11011100,
|
23
|
+
0b11011100, 0b11111100, 0b11011100, 0b11011100]
|
24
|
+
}.each do |bit_value, expected_values|
|
25
|
+
expected_values.each_with_index do |expected_value, bit_index|
|
26
|
+
context "when bit index is #{bit_index} and bit value is #{bit_value}" do
|
27
|
+
it do
|
28
|
+
expect(instance.bit_set(bit_index, bit_value))
|
29
|
+
.to eq(described_class.new(expected_value))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#from_bit_array' do
|
37
|
+
let(:bit_array) { [0, 0, 1, 1, 1, 0, 1, 1] }
|
38
|
+
|
39
|
+
{ false => 0b11011100, true => 0b00111011 }.each do |big_endian, expected_integer|
|
40
|
+
context "when big-endian is #{big_endian}" do
|
41
|
+
let(:expected_value) { described_class.new(expected_integer) }
|
42
|
+
|
43
|
+
it do
|
44
|
+
expect(described_class.from_bit_array(bit_array, big_endian)).to eq(expected_value)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it do
|
50
|
+
expect { described_class.from_bit_array([0, 0, 1, 1, 1, 0, 1]) }
|
51
|
+
.to raise_error(::ArgumentError)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|