cliutils 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.yardoc/checksums +11 -11
- data/.yardoc/object_types +0 -0
- data/.yardoc/objects/root.dat +0 -0
- data/Gemfile.lock +12 -33
- data/README.md +1 -1
- data/Rakefile +36 -31
- data/cliutils.gemspec +3 -2
- data/lib/cliutils/configuration.rb +13 -31
- data/lib/cliutils/configurator.rb +23 -62
- data/lib/cliutils/ext/Hash+Extensions.rb +39 -78
- data/lib/cliutils/ext/Logger+Extensions.rb +6 -11
- data/lib/cliutils/ext/String+Extensions.rb +25 -13
- data/lib/cliutils/logger-delegator.rb +15 -39
- data/lib/cliutils/messenging.rb +10 -28
- data/lib/cliutils/prefs.rb +18 -43
- data/lib/cliutils/pretty-io.rb +59 -127
- data/lib/cliutils/version.rb +2 -1
- data/lib/cliutils.rb +2 -0
- metadata +20 -32
- data/bin/cliutils +0 -38
- data/doc/CLIUtils/Configuration.html +0 -373
- data/doc/CLIUtils/Configurator.html +0 -873
- data/doc/CLIUtils/LoggerDelegator.html +0 -560
- data/doc/CLIUtils/Messenging.html +0 -396
- data/doc/CLIUtils/Prefs.html +0 -609
- data/doc/CLIUtils/PrettyIO.html +0 -1333
- data/doc/CLIUtils.html +0 -131
- data/doc/Hash.html +0 -672
- data/doc/Logger.html +0 -233
- data/doc/String.html +0 -562
- data/doc/_index.html +0 -207
- data/doc/class_list.html +0 -54
- data/doc/css/common.css +0 -1
- data/doc/css/full_list.css +0 -57
- data/doc/css/style.css +0 -339
- data/doc/file.README.html +0 -415
- data/doc/file_list.html +0 -56
- data/doc/frames.html +0 -26
- data/doc/index.html +0 -415
- data/doc/js/app.js +0 -219
- data/doc/js/full_list.js +0 -178
- data/doc/js/jquery.js +0 -4
- data/doc/method_list.html +0 -389
- data/doc/top-level-namespace.html +0 -114
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed57d1bb3f3c3248b082ff1ea8a5159a2e68052b
|
4
|
+
data.tar.gz: 9fb6dc3532170cdcf2ef15239d99c199fb1ef04f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da2909f0c9d6de3f3e75698b09414ea999e364894435dc7843334351568b89f5fa6292215ff7e67546b5b5918afa80083885f3b735ef303a202fc94492faf9f8
|
7
|
+
data.tar.gz: efd71929d34adea0cadecd3cc6865f48a5b3cff101de2060084994369d56f50b37d57e4a1921fb49aa9c04d16d737c3bfd38307f99580f18f2e0105af9c461bc
|
data/.gitignore
CHANGED
data/.yardoc/checksums
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
lib/cliutils.rb
|
2
|
-
lib/cliutils/prefs.rb
|
3
|
-
lib/cliutils/version.rb
|
4
|
-
lib/cliutils/pretty-io.rb
|
5
|
-
lib/cliutils/messenging.rb
|
6
|
-
lib/cliutils/configurator.rb
|
7
|
-
lib/cliutils/configuration.rb
|
8
|
-
lib/cliutils/logger-delegator.rb
|
9
|
-
lib/cliutils/ext/Hash+Extensions.rb
|
10
|
-
lib/cliutils/ext/Logger+Extensions.rb
|
11
|
-
lib/cliutils/ext/String+Extensions.rb
|
1
|
+
lib/cliutils.rb 4f397f5444c33ebcebd8384e5b7b498186785d0d
|
2
|
+
lib/cliutils/prefs.rb 66f1c006d76b5334ad4b2b427141796d35065c27
|
3
|
+
lib/cliutils/version.rb 70a1622cf96c5c986b312e8b7f5751131090b30e
|
4
|
+
lib/cliutils/pretty-io.rb fba4516ec1e2561d1b5e613e4f61b04f03e8abc0
|
5
|
+
lib/cliutils/messenging.rb c0362bcb8e1090d83966d2b3596532c7f1576570
|
6
|
+
lib/cliutils/configurator.rb c202ac417ea4891c990da586d1edf6333f0fa8d6
|
7
|
+
lib/cliutils/configuration.rb 02752324c57b7c7054d9a8158f70641cd73682bc
|
8
|
+
lib/cliutils/logger-delegator.rb 507b215088c1d019d42059832ef8280f746ee26b
|
9
|
+
lib/cliutils/ext/Hash+Extensions.rb e51f7475afccd3ad38a4a62ddcf87216f2dcc974
|
10
|
+
lib/cliutils/ext/Logger+Extensions.rb 946bf8385446f369264877a2fe6bb415f24dbcd8
|
11
|
+
lib/cliutils/ext/String+Extensions.rb a0a39b16d1709e7f5c5c4eff0d6d8258e691582d
|
data/.yardoc/object_types
CHANGED
Binary file
|
data/.yardoc/objects/root.dat
CHANGED
Binary file
|
data/Gemfile.lock
CHANGED
@@ -1,48 +1,27 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cliutils (
|
5
|
-
methadone (~> 1.3.2)
|
4
|
+
cliutils (1.0.3)
|
6
5
|
|
7
6
|
GEM
|
8
7
|
remote: https://rubygems.org/
|
9
8
|
specs:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
ffi (~> 1.0, >= 1.0.11)
|
17
|
-
cucumber (1.3.12)
|
18
|
-
builder (>= 2.1.2)
|
19
|
-
diff-lcs (>= 1.1.3)
|
20
|
-
gherkin (~> 2.12)
|
21
|
-
multi_json (>= 1.7.5, < 2.0)
|
22
|
-
multi_test (>= 0.1.1)
|
23
|
-
diff-lcs (1.2.5)
|
24
|
-
ffi (1.9.3)
|
25
|
-
gherkin (2.12.2)
|
26
|
-
multi_json (~> 1.3)
|
27
|
-
json (1.8.1)
|
28
|
-
methadone (1.3.2)
|
29
|
-
bundler
|
30
|
-
multi_json (1.9.2)
|
31
|
-
multi_test (0.1.1)
|
9
|
+
coderay (1.1.0)
|
10
|
+
method_source (0.8.2)
|
11
|
+
pry (0.9.12.6)
|
12
|
+
coderay (~> 1.0)
|
13
|
+
method_source (~> 0.8)
|
14
|
+
slop (~> 3.4)
|
32
15
|
rake (0.9.2.2)
|
33
|
-
|
34
|
-
|
35
|
-
rspec-expectations (3.0.0.beta2)
|
36
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
-
rspec-support (= 3.0.0.beta2)
|
38
|
-
rspec-support (3.0.0.beta2)
|
16
|
+
slop (3.5.0)
|
17
|
+
yard (0.8.7.4)
|
39
18
|
|
40
19
|
PLATFORMS
|
41
20
|
ruby
|
42
21
|
|
43
22
|
DEPENDENCIES
|
44
|
-
aruba
|
45
23
|
bundler (~> 1.5)
|
46
24
|
cliutils!
|
47
|
-
|
48
|
-
|
25
|
+
pry (~> 0.9)
|
26
|
+
rake (~> 0)
|
27
|
+
yard (= 0.8.7.4)
|
data/README.md
CHANGED
@@ -45,7 +45,7 @@ include CLIUtils
|
|
45
45
|
|
46
46
|
Alternatively, as described below, mix in only the libraries that you want.
|
47
47
|
|
48
|
-
Note that although this README.md is extensive, it may not cover all methods. Check out the [tests](https://github.com/bachya/cli-utils/tree/master/test) to see more examples.
|
48
|
+
Note that although this README.md is extensive, it may not cover all methods. Check out the [YARD documentation](http://rubydoc.info/github/bachya/cli-utils/master/frames) and the [tests](https://github.com/bachya/cli-utils/tree/master/test) to see more examples.
|
49
49
|
|
50
50
|
# Libraries
|
51
51
|
|
data/Rakefile
CHANGED
@@ -1,45 +1,50 @@
|
|
1
1
|
require 'rake/clean'
|
2
2
|
require 'rubygems'
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
Rake::RDocTask.new do |rd|
|
8
|
-
rd.main = "README.md"
|
9
|
-
rd.rdoc_files.include("README.md","lib/**/**/*.rb")
|
10
|
-
rd.title = 'CLIUtils'
|
3
|
+
|
4
|
+
def version
|
5
|
+
contents = File.read File.expand_path('../lib/cliutils/version.rb', __FILE__)
|
6
|
+
contents[/VERSION = "([^"]+)"/, 1]
|
11
7
|
end
|
12
8
|
|
13
9
|
spec = eval(File.read('cliutils.gemspec'))
|
14
10
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
CLEAN << CUKE_RESULTS
|
19
|
-
desc 'Run features'
|
20
|
-
Cucumber::Rake::Task.new(:features) do |t|
|
21
|
-
opts = "features --format html -o #{CUKE_RESULTS} --format progress -x"
|
22
|
-
opts += " --tags #{ENV['TAGS']}" if ENV['TAGS']
|
23
|
-
t.cucumber_opts = opts
|
24
|
-
t.fork = false
|
25
|
-
end
|
26
|
-
|
27
|
-
desc 'Run features tagged as work-in-progress (@wip)'
|
28
|
-
Cucumber::Rake::Task.new('features:wip') do |t|
|
29
|
-
tag_opts = ' --tags ~@pending'
|
30
|
-
tag_opts = ' --tags @wip'
|
31
|
-
t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty -x -s#{tag_opts}"
|
32
|
-
t.fork = false
|
11
|
+
require 'yard'
|
12
|
+
desc 'Create YARD documentation'
|
13
|
+
YARD::Rake::YardocTask.new do |t|
|
33
14
|
end
|
34
15
|
|
35
|
-
task :cucumber => :features
|
36
|
-
task 'cucumber:wip' => 'features:wip'
|
37
|
-
task :wip => 'features:wip'
|
38
|
-
|
39
16
|
require 'rake/testtask'
|
17
|
+
desc 'Run unit tests'
|
40
18
|
Rake::TestTask.new do |t|
|
41
19
|
t.libs << "test"
|
42
20
|
t.test_files = FileList['test/*_test.rb']
|
43
21
|
end
|
44
22
|
|
45
|
-
|
23
|
+
require 'pry'
|
24
|
+
desc 'Open up a PRY session with this gem loaded'
|
25
|
+
task :pry do
|
26
|
+
puts version
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "Release CLIUtils version #{version}"
|
30
|
+
task :release => :build do
|
31
|
+
unless `git branch` =~ /^\* master$/
|
32
|
+
puts "You must be on the master branch to release!"
|
33
|
+
exit!
|
34
|
+
end
|
35
|
+
|
36
|
+
sh "git commit --allow-empty -a -m 'Release #{version}'"
|
37
|
+
sh "git tag v#{version}"
|
38
|
+
sh "git push origin master"
|
39
|
+
sh "git push origin v#{version}"
|
40
|
+
sh "gem push pkg/cliutils-#{version}.gem"
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "Build the gem"
|
44
|
+
task :build do
|
45
|
+
FileUtils.mkdir_p "pkg"
|
46
|
+
sh "gem build cliutils.gemspec"
|
47
|
+
FileUtils.mv("./cliutils-#{version}.gem", "pkg")
|
48
|
+
end
|
49
|
+
|
50
|
+
task :default => :test
|
data/cliutils.gemspec
CHANGED
@@ -22,7 +22,8 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.extra_rdoc_files = ['README.md', 'doc']
|
23
23
|
spec.rdoc_options << '--title' << 'CLIUtils' << '--main' << 'README.md' << '-ri'
|
24
24
|
|
25
|
-
spec.add_development_dependency(
|
26
|
-
spec.add_development_dependency('
|
25
|
+
spec.add_development_dependency('bundler', '~> 1.5')
|
26
|
+
spec.add_development_dependency('pry', '~> 0.9')
|
27
27
|
spec.add_development_dependency('rake', '~> 0')
|
28
|
+
spec.add_development_dependency('yard', '0.8.7.4')
|
28
29
|
end
|
@@ -1,46 +1,28 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
|
3
3
|
module CLIUtils
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# Manages any configuration values and the flat YAML file
|
8
|
-
# into which they get stored.
|
9
|
-
# ======================================================
|
4
|
+
# Configuration Module
|
5
|
+
# Manages any configuration values and the flat YAML file
|
6
|
+
# into which they get stored.
|
10
7
|
module Configuration
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# ----------------------------------------------------
|
15
|
-
# included method
|
16
|
-
#
|
17
|
-
# Hook called when this module gets mixed in; extends
|
18
|
-
# the includer with the methods defined here.
|
19
|
-
# @param k The includer
|
20
|
-
# @return Void
|
21
|
-
# ----------------------------------------------------
|
8
|
+
# Hook that triggers when this module is included.
|
9
|
+
# @param [Object] k The includer object
|
10
|
+
# @return [void]
|
22
11
|
def self.included(k)
|
23
12
|
k.extend(self)
|
24
13
|
end
|
25
14
|
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
# Singleton method to return (or initialize, if needed)
|
30
|
-
# a Configurator.
|
31
|
-
# @return Configurator
|
32
|
-
# ----------------------------------------------------
|
15
|
+
# Singleton method to return (or initialize, if needed)
|
16
|
+
# a Configurator.
|
17
|
+
# @return [Configurator]
|
33
18
|
def configuration
|
34
19
|
@configuration ||= Configurator.new('~/.default-cliutils')
|
35
20
|
end
|
36
21
|
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
# @param path The path to the config file
|
42
|
-
# @return Void
|
43
|
-
# ----------------------------------------------------
|
22
|
+
# Singleton method to return (or initialize, if needed)
|
23
|
+
# a Configurator.
|
24
|
+
# @param [String] path The filepath to use
|
25
|
+
# @return [void]
|
44
26
|
def load_configuration(path)
|
45
27
|
@configuration = Configurator.new(path)
|
46
28
|
end
|
@@ -1,28 +1,15 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
|
3
3
|
module CLIUtils
|
4
|
-
# ======================================================
|
5
4
|
# Configuration Class
|
6
|
-
#
|
7
5
|
# Manages any configuration values and the flat YAML file
|
8
6
|
# into which they get stored.
|
9
|
-
# ======================================================
|
10
7
|
class Configurator
|
11
|
-
# ====================================================
|
12
|
-
# Attributes
|
13
|
-
# ====================================================
|
14
8
|
attr_reader :config_path, :data
|
15
9
|
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
# ----------------------------------------------------
|
20
|
-
# initialize method
|
21
|
-
#
|
22
|
-
# Initializes configuration from a flat file.
|
23
|
-
# @param path The filepath to the config YAML
|
24
|
-
# @return void
|
25
|
-
# ----------------------------------------------------
|
10
|
+
# Initializes configuration from a flat file.
|
11
|
+
# @param [String] path The filepath to the config YAML
|
12
|
+
# @return [void]
|
26
13
|
def initialize(path)
|
27
14
|
_path = File.expand_path(path)
|
28
15
|
@config_path = _path
|
@@ -34,14 +21,10 @@ module CLIUtils
|
|
34
21
|
end
|
35
22
|
end
|
36
23
|
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
# already exist).
|
42
|
-
# @param section_name The section to add
|
43
|
-
# @return Void
|
44
|
-
# ----------------------------------------------------
|
24
|
+
# Adds a new section to the config file (if it doesn't
|
25
|
+
# already exist).
|
26
|
+
# @param [String] section_name The section to add
|
27
|
+
# @return [void]
|
45
28
|
def add_section(section_name)
|
46
29
|
if !@data.key?(section_name)
|
47
30
|
@data[section_name] = {}
|
@@ -50,13 +33,9 @@ module CLIUtils
|
|
50
33
|
end
|
51
34
|
end
|
52
35
|
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
# Removes a section to the config file (if it exists).
|
57
|
-
# @param section_name The section to remove
|
58
|
-
# @return Void
|
59
|
-
# ----------------------------------------------------
|
36
|
+
# Removes a section to the config file (if it exists).
|
37
|
+
# @param [String] section_name The section to remove
|
38
|
+
# @return [void]
|
60
39
|
def delete_section(section_name)
|
61
40
|
if @data.key?(section_name)
|
62
41
|
@data.delete(section_name)
|
@@ -65,14 +44,10 @@ module CLIUtils
|
|
65
44
|
end
|
66
45
|
end
|
67
46
|
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
# configuration data.
|
73
|
-
# @param prefs The Prefs class to examine
|
74
|
-
# @return Void
|
75
|
-
# ----------------------------------------------------
|
47
|
+
# Ingests a Prefs class and adds its answers to the
|
48
|
+
# configuration data.
|
49
|
+
# @param [Prefs] prefs The Prefs class to examine
|
50
|
+
# @return [void]
|
76
51
|
def ingest_prefs(prefs)
|
77
52
|
fail 'Invaid Prefs class' if !prefs.kind_of?(Prefs) || prefs.answers.nil?
|
78
53
|
prefs.answers.each do |p|
|
@@ -81,37 +56,23 @@ module CLIUtils
|
|
81
56
|
end
|
82
57
|
end
|
83
58
|
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
# Hash when given a method name that matches a key.
|
89
|
-
# @param name
|
90
|
-
# @param *args
|
91
|
-
# @param &block
|
92
|
-
# @return Hash
|
93
|
-
# ----------------------------------------------------
|
59
|
+
# Hook that fires when a non-existent method is called.
|
60
|
+
# Allows this module to return data from the config
|
61
|
+
# Hash when given a method name that matches a key.
|
62
|
+
# @return [Hash]
|
94
63
|
def method_missing(name, *args, &block)
|
95
64
|
@data[name.to_sym] || @data.merge!(name.to_sym => {})
|
96
65
|
end
|
97
66
|
|
98
|
-
#
|
99
|
-
#
|
100
|
-
#
|
101
|
-
# Clears the configuration data.
|
102
|
-
# @return Void
|
103
|
-
# ----------------------------------------------------
|
67
|
+
# Clears the configuration data.
|
68
|
+
# @return [void]
|
104
69
|
def reset
|
105
70
|
@data = {}
|
106
71
|
end
|
107
72
|
|
108
|
-
#
|
109
|
-
#
|
110
|
-
#
|
111
|
-
# Saves the configuration data to the previously
|
112
|
-
# stored flat file.
|
113
|
-
# @return Void
|
114
|
-
# ----------------------------------------------------
|
73
|
+
# Saves the configuration data to the previously
|
74
|
+
# stored flat file.
|
75
|
+
# @return [void]
|
115
76
|
def save
|
116
77
|
File.open(@config_path, 'w') { |f| f.write(@data.deep_stringify_keys.to_yaml) }
|
117
78
|
end
|
@@ -1,21 +1,12 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
4
|
-
# Contains many convenient methods borrowed from Rails
|
5
|
-
# http://api.rubyonrails.org/classes/Hash.html
|
6
|
-
# ======================================================
|
1
|
+
# Hash Class
|
2
|
+
# Contains many convenient methods borrowed from Rails
|
3
|
+
# http://api.rubyonrails.org/classes/Hash.html
|
7
4
|
class Hash
|
8
|
-
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# Deep merges a hash into the current one.
|
15
|
-
# @param other_hash The hash to merge in
|
16
|
-
# @param &block
|
17
|
-
# @return Hash
|
18
|
-
# ----------------------------------------------------
|
5
|
+
|
6
|
+
# Deep merges a hash into the current one.
|
7
|
+
# @param [Hash] other_hash The hash to merge in
|
8
|
+
# @yield &block
|
9
|
+
# @return [Hash]
|
19
10
|
def deep_merge!(other_hash, &block)
|
20
11
|
other_hash.each_pair do |k,v|
|
21
12
|
tv = self[k]
|
@@ -28,84 +19,58 @@ class Hash
|
|
28
19
|
self
|
29
20
|
end
|
30
21
|
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
# Recursively turns all Hash keys into strings and
|
35
|
-
# returns the new Hash.
|
36
|
-
# @return Hash
|
37
|
-
# ----------------------------------------------------
|
22
|
+
# Recursively turns all Hash keys into strings and
|
23
|
+
# returns the new Hash.
|
24
|
+
# @return [Hash]
|
38
25
|
def deep_stringify_keys
|
39
26
|
deep_transform_keys{ |key| key.to_s }
|
40
27
|
end
|
41
28
|
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
# Same as deep_stringify_keys, but destructively
|
46
|
-
# alters the original Hash.
|
47
|
-
# @return Hash
|
48
|
-
# ----------------------------------------------------
|
29
|
+
# Same as deep_stringify_keys, but destructively
|
30
|
+
# alters the original Hash.
|
31
|
+
# @return [Hash]
|
49
32
|
def deep_stringify_keys!
|
50
33
|
deep_transform_keys!{ |key| key.to_s }
|
51
34
|
end
|
52
35
|
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
# Recursively turns all Hash keys into symbols and
|
57
|
-
# returns the new Hash.
|
58
|
-
# @return Hash
|
59
|
-
# ----------------------------------------------------
|
36
|
+
# Recursively turns all Hash keys into symbols and
|
37
|
+
# returns the new Hash.
|
38
|
+
# @return [Hash]
|
60
39
|
def deep_symbolize_keys
|
61
40
|
deep_transform_keys{ |key| key.to_sym rescue key }
|
62
41
|
end
|
63
42
|
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
67
|
-
# Same as deep_symbolize_keys, but destructively
|
68
|
-
# alters the original Hash.
|
69
|
-
# @return Hash
|
70
|
-
# ----------------------------------------------------
|
43
|
+
# Same as deep_symbolize_keys, but destructively
|
44
|
+
# alters the original Hash.
|
45
|
+
# @return [Hash]
|
71
46
|
def deep_symbolize_keys!
|
72
47
|
deep_transform_keys!{ |key| key.to_sym rescue key }
|
73
48
|
end
|
74
49
|
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
78
|
-
#
|
79
|
-
# Hash.
|
80
|
-
# @return Hash
|
81
|
-
# ----------------------------------------------------
|
50
|
+
# Generic method to perform recursive operations on a
|
51
|
+
# Hash.
|
52
|
+
# @yield &block
|
53
|
+
# @return [Hash]
|
82
54
|
def deep_transform_keys(&block)
|
83
55
|
_deep_transform_keys_in_object(self, &block)
|
84
56
|
end
|
85
57
|
|
86
|
-
#
|
87
|
-
#
|
88
|
-
#
|
89
|
-
#
|
90
|
-
# alters the original Hash.
|
91
|
-
# @return Hash
|
92
|
-
# ----------------------------------------------------
|
58
|
+
# Same as deep_transform_keys, but destructively
|
59
|
+
# alters the original Hash.
|
60
|
+
# @yield &block
|
61
|
+
# @return [Hash]
|
93
62
|
def deep_transform_keys!(&block)
|
94
63
|
_deep_transform_keys_in_object!(self, &block)
|
95
64
|
end
|
96
65
|
|
97
66
|
private
|
98
67
|
|
99
|
-
#
|
100
|
-
#
|
101
|
-
#
|
102
|
-
#
|
103
|
-
#
|
104
|
-
#
|
105
|
-
# @param object The object to examine
|
106
|
-
# @param &block A block to execute on the opject
|
107
|
-
# @return Object
|
108
|
-
# ----------------------------------------------------
|
68
|
+
# Modification to deep_transform_keys that allows for
|
69
|
+
# the existence of arrays.
|
70
|
+
# https://github.com/rails/rails/pull/9720/files?short_path=4be3c90
|
71
|
+
# @param [Object] object The object to examine
|
72
|
+
# @yield &block
|
73
|
+
# @return [Object]
|
109
74
|
def _deep_transform_keys_in_object(object, &block)
|
110
75
|
case object
|
111
76
|
when Hash
|
@@ -119,15 +84,11 @@ class Hash
|
|
119
84
|
end
|
120
85
|
end
|
121
86
|
|
122
|
-
#
|
123
|
-
#
|
124
|
-
#
|
125
|
-
#
|
126
|
-
#
|
127
|
-
# @param object The object to examine
|
128
|
-
# @param &block A block to execute on the opject
|
129
|
-
# @return Object
|
130
|
-
# ----------------------------------------------------
|
87
|
+
# Same as _deep_transform_keys_in_object, but
|
88
|
+
# destructively alters the original Object.
|
89
|
+
# @param [Object] The object to examine
|
90
|
+
# @yield &block
|
91
|
+
# @return [Object]
|
131
92
|
def _deep_transform_keys_in_object!(object, &block)
|
132
93
|
case object
|
133
94
|
when Hash
|
@@ -1,17 +1,12 @@
|
|
1
1
|
require 'logger'
|
2
2
|
|
3
|
-
#
|
4
|
-
# Logger Class
|
5
|
-
# ======================================================
|
3
|
+
# Logger Class extensions
|
6
4
|
class Logger
|
7
|
-
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# @param tag The Logger level to create
|
13
|
-
# @return Void
|
14
|
-
# ----------------------------------------------------
|
5
|
+
|
6
|
+
# Creates a custom Logger level based on the passed
|
7
|
+
# tag.
|
8
|
+
# @param [String] tag The Logger level to create
|
9
|
+
# @return [void]
|
15
10
|
def self.custom_level(tag)
|
16
11
|
SEV_LABEL << tag
|
17
12
|
idx = SEV_LABEL.size - 1
|
@@ -1,26 +1,38 @@
|
|
1
|
-
#
|
2
|
-
# String Class
|
3
|
-
# ======================================================
|
1
|
+
# String Class extensions
|
4
2
|
class String
|
5
|
-
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# colorize method
|
10
|
-
#
|
11
|
-
# Outputs a string in a formatted color.
|
12
|
-
# @param color_code The code to use
|
13
|
-
# @return Void
|
14
|
-
# ----------------------------------------------------
|
3
|
+
|
4
|
+
# Outputs a string in a formatted color.
|
5
|
+
# @param [<Integer, String>] color_code The code to use
|
6
|
+
# @return [void]
|
15
7
|
def colorize(color_code)
|
16
8
|
"\033[#{ color_code }m#{ self }\033[0m"
|
17
9
|
end
|
18
10
|
|
11
|
+
# Makes the associated string blue.
|
12
|
+
# @return [void]
|
19
13
|
def blue; colorize(34) end
|
14
|
+
|
15
|
+
# Makes the associated string cyan.
|
16
|
+
# @return [void]
|
20
17
|
def cyan; colorize(36) end
|
18
|
+
|
19
|
+
# Makes the associated string green.
|
20
|
+
# @return [void]
|
21
21
|
def green; colorize(32) end
|
22
|
+
|
23
|
+
# Makes the associated string purple.
|
24
|
+
# @return [void]
|
22
25
|
def purple; colorize(35) end
|
26
|
+
|
27
|
+
# Makes the associated string red.
|
28
|
+
# @return [void]
|
23
29
|
def red; colorize(31) end
|
30
|
+
|
31
|
+
# Makes the associated string white.
|
32
|
+
# @return [void]
|
24
33
|
def white; colorize(37) end
|
34
|
+
|
35
|
+
# Makes the associated string yellow.
|
36
|
+
# @return [void]
|
25
37
|
def yellow; colorize(33) end
|
26
38
|
end
|