flazm_ruby_helpers 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +8 -0
- data/LICENSE +21 -0
- data/README.md +2 -0
- data/Rakefile +14 -0
- data/VERSION +1 -0
- data/flazm_ruby_helpers.gemspec +24 -0
- data/lib/flazm_ruby_helpers/class_helper.rb +21 -0
- data/lib/flazm_ruby_helpers/data_structures.rb +78 -0
- data/lib/flazm_ruby_helpers/rake_helper.rb +49 -0
- data/pkg/consul_watcher-0.0.1.gem +0 -0
- data/pkg/flazm_ruby_helpers-0.0.1.gem +0 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a5cf0748fd56bb9c92fd5e26d4f636255ef78bd4647502293421b7b74a6db7d5
|
4
|
+
data.tar.gz: a93aeea8bbec25c4383cbfa608e58e65ee8380be0efd951957c302916d9d589a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e5b1fd8ba4d351a904e8e13cb944cd22ae2caadc613884e5b9eee2b9748f1382329ba127dd2c04c40d35ef42f69a83c6c8a8d7d7c246049626f51d7a372151f3
|
7
|
+
data.tar.gz: 50cac9775f4bc39a8d290beea1e62803b51f5035d7738f47f1320fece0bfe4712ec3d35b37b0e8f0d66522add06a1995ad3459175519d824ecf55db07263a866
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 Ryan Fortman
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'open3'
|
5
|
+
require_relative 'lib/flazm_ruby_helpers/rake_helper'
|
6
|
+
|
7
|
+
spec_file = Gem::Specification.load('flazm_ruby_helpers.gemspec')
|
8
|
+
|
9
|
+
task default: :build
|
10
|
+
|
11
|
+
task :publish do
|
12
|
+
cmd_gem = "gem push pkg/flazm_ruby_helpers-#{spec_file.version}.gem"
|
13
|
+
_output, _status = FlazmRubyHelpers::RakeHelper.exec(cmd_gem)
|
14
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', '..')
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'flazm_ruby_helpers'
|
8
|
+
spec.version = IO.read('VERSION').chomp
|
9
|
+
spec.authors = ['Ryan Fortman']
|
10
|
+
spec.email = ['r.fortman.dev@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Misc (flazm) helpers for ruby. Class extensions and static methods'
|
13
|
+
spec.homepage = 'https://github.com/fortman/flazm_ruby_helpers'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_runtime_dependency 'bundler', '~> 2.0'
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FlazmRubyHelpers
|
4
|
+
# Define methods to handle default initialization behavior
|
5
|
+
module ClassHelper
|
6
|
+
def initialize_variables(config = {})
|
7
|
+
# define the defaults method in the class that includes this
|
8
|
+
# defaults method returns a hash of instance variables mapped to values
|
9
|
+
defaults.each_pair do |key, default_value|
|
10
|
+
key = key.to_s
|
11
|
+
if config[key]
|
12
|
+
instance_variable_set("@#{key}", config[key])
|
13
|
+
elsif ENV[key.upcase.to_s]
|
14
|
+
instance_variable_set("@#{key}", ENV[key.upcase.to_s])
|
15
|
+
else
|
16
|
+
instance_variable_set("@#{key}", default_value)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
# Adding transversal logic
|
7
|
+
class ::Array # rubocop:disable Style/ClassAndModuleChildren
|
8
|
+
def walk_values(vproc)
|
9
|
+
map do |array_item|
|
10
|
+
array_item.is_a?(Hash) || array_item.is_a?(Array) ? array_item.walk_values(vproc) : vproc.call(array_item)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def walk_keys(kproc)
|
15
|
+
map do |array_item|
|
16
|
+
array_item.is_a?(Hash) || array_item.is_a?(Array) ? array_item.walk_keys(kproc) : array_item
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_yaml_inline(pad_left_indents: 0, indent_size: 2)
|
21
|
+
indent_string = ' ' * indent_size
|
22
|
+
pad_indent = indent_string * pad_left_indents
|
23
|
+
result = JSON.parse(to_json).to_yaml(indentation: indent_size, line_width: -1).to_str.lines.to_a[1..-1].collect \
|
24
|
+
{ |line| pad_indent + line }
|
25
|
+
result.join
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Ruby hash extensions
|
30
|
+
class ::Hash # rubocop:disable Style/ClassAndModuleChildren
|
31
|
+
def deep_merge(second)
|
32
|
+
merger = proc { |_key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 } # rubocop:disable Style/CaseEquality, Metrics/LineLength
|
33
|
+
merge(second, &merger)
|
34
|
+
end
|
35
|
+
|
36
|
+
def walk_values(vproc)
|
37
|
+
map do |key, value|
|
38
|
+
value.is_a?(Hash) || value.is_a?(Array) ? { key => value.walk_values(vproc) } : { key => vproc.call(value) }
|
39
|
+
end.reduce({}, :merge)
|
40
|
+
end
|
41
|
+
|
42
|
+
def walk_keys(kproc)
|
43
|
+
map do |key, value|
|
44
|
+
if value.is_a?(Hash) || value.is_a?(Array)
|
45
|
+
{ kproc.call(key) => value.walk_keys(kproc) }
|
46
|
+
else
|
47
|
+
{ kproc.call(key) => value }
|
48
|
+
end
|
49
|
+
end.reduce({}, :merge)
|
50
|
+
end
|
51
|
+
|
52
|
+
def leaf_node?
|
53
|
+
map do |_key, value|
|
54
|
+
return false if value.is_a?(Hash) || value.is_a?(Array)
|
55
|
+
end
|
56
|
+
true
|
57
|
+
end
|
58
|
+
|
59
|
+
def flatten_paths(path_prefix = '')
|
60
|
+
result = {}
|
61
|
+
map do |key, value|
|
62
|
+
if value.is_a?(Hash)
|
63
|
+
result.merge!(value.flatten_paths("#{path_prefix}/#{key}"))
|
64
|
+
else
|
65
|
+
result.merge!("#{path_prefix}/#{key}" => value)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
result
|
69
|
+
end
|
70
|
+
|
71
|
+
def to_yaml_inline(pad_left_indents: 0, indent_size: 2)
|
72
|
+
indent_string = ' ' * indent_size
|
73
|
+
pad_indent = indent_string * pad_left_indents
|
74
|
+
result = JSON.parse(to_json).to_yaml(indentation: indent_size, line_width: -1).to_str.lines.to_a[1..-1].map \
|
75
|
+
{ |line| pad_indent + line }
|
76
|
+
result.join
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
require 'open3'
|
6
|
+
require 'net/http'
|
7
|
+
require 'bunny'
|
8
|
+
require 'json'
|
9
|
+
|
10
|
+
module FlazmRubyHelpers
|
11
|
+
module RakeHelper
|
12
|
+
def self.exec(command, stream: true)
|
13
|
+
output = [] ; threads = [] ; status = nil
|
14
|
+
Open3.popen3(command) do |_stdin, stdout, stderr, wait_thr|
|
15
|
+
{ out: stdout, err: stderr }.each do |_key, stream|
|
16
|
+
threads << Thread.new do
|
17
|
+
until (raw_line = stream.gets).nil?
|
18
|
+
output << raw_line.to_s
|
19
|
+
puts raw_line.to_s if stream
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
threads.each(&:join)
|
24
|
+
status = wait_thr.value.success?
|
25
|
+
end
|
26
|
+
return output, status
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.wait_for_urls(urls)
|
30
|
+
urls.each do |url|
|
31
|
+
uri = URI(url)
|
32
|
+
error = true
|
33
|
+
Net::HTTP.start(uri.host, uri.port, read_timeout: 5, max_retries: 12) do |http|
|
34
|
+
while error
|
35
|
+
begin
|
36
|
+
response = http.request(Net::HTTP::Get.new(uri))
|
37
|
+
error = false
|
38
|
+
rescue EOFError
|
39
|
+
retry
|
40
|
+
end
|
41
|
+
end
|
42
|
+
raise Exception unless response.code == '200'
|
43
|
+
|
44
|
+
puts "up: #{url}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
Binary file
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flazm_ruby_helpers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Fortman
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '10.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '10.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- r.fortman.dev@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- Gemfile
|
49
|
+
- LICENSE
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- VERSION
|
53
|
+
- flazm_ruby_helpers.gemspec
|
54
|
+
- lib/flazm_ruby_helpers/class_helper.rb
|
55
|
+
- lib/flazm_ruby_helpers/data_structures.rb
|
56
|
+
- lib/flazm_ruby_helpers/rake_helper.rb
|
57
|
+
- pkg/consul_watcher-0.0.1.gem
|
58
|
+
- pkg/flazm_ruby_helpers-0.0.1.gem
|
59
|
+
homepage: https://github.com/fortman/flazm_ruby_helpers
|
60
|
+
licenses: []
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.7.8
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: Misc (flazm) helpers for ruby. Class extensions and static methods
|
82
|
+
test_files: []
|