bblib 2.0.4 → 2.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +12 -12
- data/.rspec +2 -2
- data/.travis.yml +4 -4
- data/CODE_OF_CONDUCT.md +13 -13
- data/Gemfile +4 -4
- data/LICENSE.txt +21 -21
- data/Rakefile +6 -6
- data/bblib.gemspec +34 -34
- data/bin/console +14 -14
- data/bin/setup +7 -7
- data/lib/bblib.rb +1 -1
- data/lib/bblib/all.rb +6 -6
- data/lib/bblib/color.rb +2 -0
- data/lib/bblib/core/classes/tree_hash.rb +15 -10
- data/lib/bblib/core/hash_path/part.rb +1 -1
- data/lib/bblib/core/mixins/attrs.rb +7 -3
- data/lib/bblib/core/mixins/bridge.rb +2 -2
- data/lib/bblib/core/mixins/hooks.rb +15 -14
- data/lib/bblib/core/util/cases.rb +4 -2
- data/lib/bblib/core/util/file.rb +10 -0
- data/lib/bblib/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bcadfffa41731b8ab5a58b196fca73aea9384e26bfe5e81100cf0bd0033ea3ec
|
4
|
+
data.tar.gz: 5c88fe561fd296d4afd00e45fbf4bc3ef0a00fce97cf856b4147ba3cac355cd6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68c2fc30a33000acfd217b9f3059f4df44420dde884169f38c317ecfa9107394b4f87434886bf1fa2cc36131be65e20c3e8d58f74eb5f68923862d797de11dd9
|
7
|
+
data.tar.gz: 83cf1780e76795efa2aeaf20bb41b7b482d13fd25891929e736c5163800ddd3008f919d65d52f07504f24e7942900af1262e86e4c5534d1753cfe275b6d5d250
|
data/.gitignore
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
/.bundle/
|
2
|
-
/.yardoc
|
3
|
-
/Gemfile.lock
|
4
|
-
/_yardoc/
|
5
|
-
/coverage/
|
6
|
-
/doc/
|
7
|
-
/pkg/
|
8
|
-
/spec/reports/
|
9
|
-
/tmp/
|
10
|
-
/spec/coverage/
|
11
|
-
*.gem
|
12
|
-
smells.html
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
10
|
+
/spec/coverage/
|
11
|
+
*.gem
|
12
|
+
smells.html
|
data/.rspec
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
--format documentation
|
2
|
-
--color
|
1
|
+
--format documentation
|
2
|
+
--color
|
data/.travis.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 2.1.6
|
4
|
-
before_install: gem install bundler -v 1.10.6
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.1.6
|
4
|
+
before_install: gem install bundler -v 1.10.6
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
# Contributor Code of Conduct
|
2
|
-
|
3
|
-
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
-
|
5
|
-
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
-
|
7
|
-
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
-
|
9
|
-
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
-
|
11
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
-
|
13
|
-
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in bblib.gemspec
|
4
|
-
gemspec
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in bblib.gemspec
|
4
|
+
gemspec
|
data/LICENSE.txt
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2015 Brandon
|
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
|
13
|
-
all 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
|
21
|
-
THE SOFTWARE.
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Brandon
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
require "rspec/core/rake_task"
|
3
|
-
|
4
|
-
RSpec::Core::RakeTask.new(:spec)
|
5
|
-
|
6
|
-
task :default => :spec
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
|
6
|
+
task :default => :spec
|
data/bblib.gemspec
CHANGED
@@ -1,34 +1,34 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'bblib/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "bblib"
|
8
|
-
spec.version = BBLib::VERSION
|
9
|
-
spec.authors = ["Brandon Black"]
|
10
|
-
spec.email = ["d2sm10@hotmail.com"]
|
11
|
-
|
12
|
-
spec.summary = %q{A library containing many reusable, basic functions.}
|
13
|
-
spec.description = %q{A library containing many reusable, basic functions.}
|
14
|
-
spec.homepage = "https://github.com/bblack16/bblib-ruby"
|
15
|
-
spec.license = "MIT"
|
16
|
-
|
17
|
-
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
-
# delete this section to allow pushing this gem to any host.
|
19
|
-
# if spec.respond_to?(:metadata)
|
20
|
-
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
-
# else
|
22
|
-
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
-
# end
|
24
|
-
|
25
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) || f.end_with?('.gem') }
|
26
|
-
spec.bindir = "exe"
|
27
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
-
spec.require_paths = ["lib"]
|
29
|
-
|
30
|
-
spec.add_development_dependency "bundler", "~> 1.10"
|
31
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
-
spec.add_development_dependency "rspec"
|
33
|
-
spec.add_development_dependency "simplecov"
|
34
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bblib/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bblib"
|
8
|
+
spec.version = BBLib::VERSION
|
9
|
+
spec.authors = ["Brandon Black"]
|
10
|
+
spec.email = ["d2sm10@hotmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A library containing many reusable, basic functions.}
|
13
|
+
spec.description = %q{A library containing many reusable, basic functions.}
|
14
|
+
spec.homepage = "https://github.com/bblack16/bblib-ruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
# end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) || f.end_with?('.gem') }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "rspec"
|
33
|
+
spec.add_development_dependency "simplecov"
|
34
|
+
end
|
data/bin/console
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "bblib"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "bblib"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
set -euo pipefail
|
3
|
-
IFS=$'\n\t'
|
4
|
-
|
5
|
-
bundle install
|
6
|
-
|
7
|
-
# Do any other automated setup that you need to do here
|
1
|
+
#!/bin/bash
|
2
|
+
set -euo pipefail
|
3
|
+
IFS=$'\n\t'
|
4
|
+
|
5
|
+
bundle install
|
6
|
+
|
7
|
+
# Do any other automated setup that you need to do here
|
data/lib/bblib.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require_relative 'bblib/core'
|
1
|
+
require_relative 'bblib/core'
|
data/lib/bblib/all.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require_relative 'core'
|
2
|
-
require_relative 'cli'
|
3
|
-
require_relative 'system'
|
4
|
-
require_relative 'html'
|
5
|
-
require_relative 'cron'
|
6
|
-
require_relative 'fuzzy_matcher'
|
1
|
+
require_relative 'core'
|
2
|
+
require_relative 'cli'
|
3
|
+
require_relative 'system'
|
4
|
+
require_relative 'html'
|
5
|
+
require_relative 'cron'
|
6
|
+
require_relative 'fuzzy_matcher'
|
data/lib/bblib/color.rb
ADDED
@@ -36,7 +36,7 @@ class TreeHash
|
|
36
36
|
case
|
37
37
|
when Hash >= node_class
|
38
38
|
children.include?(key) || (!symbol_sensitive && children.include?(key.to_s.to_sym))
|
39
|
-
when Array >= node_class
|
39
|
+
when Array >= node_class && key.respond_to?(:to_i)
|
40
40
|
[0...children.size] === key.to_i
|
41
41
|
else
|
42
42
|
false
|
@@ -44,13 +44,13 @@ class TreeHash
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def children?
|
47
|
-
(node_class
|
47
|
+
(node_class <= Hash || node_class <= Array) && !children.empty?
|
48
48
|
end
|
49
49
|
|
50
50
|
def descendants
|
51
51
|
return [] unless children?
|
52
52
|
desc = []
|
53
|
-
children.each do |
|
53
|
+
children.each do |_key, child|
|
54
54
|
desc << child
|
55
55
|
desc += child.descendants if child.children?
|
56
56
|
end
|
@@ -198,7 +198,7 @@ class TreeHash
|
|
198
198
|
end
|
199
199
|
|
200
200
|
def process(processor, &block)
|
201
|
-
# TODO Add ability to process values or keys in tree hashes
|
201
|
+
# TODO: Add ability to process values or keys in tree hashes
|
202
202
|
end
|
203
203
|
|
204
204
|
def size
|
@@ -206,8 +206,7 @@ class TreeHash
|
|
206
206
|
end
|
207
207
|
|
208
208
|
def paths
|
209
|
-
|
210
|
-
when Array >= node_class, Hash >= node_class
|
209
|
+
if Array >= node_class || Hash >= node_class
|
211
210
|
value.squish.keys
|
212
211
|
else
|
213
212
|
[]
|
@@ -342,10 +341,10 @@ class TreeHash
|
|
342
341
|
|
343
342
|
def build_from(object)
|
344
343
|
@children = {}
|
345
|
-
case
|
346
|
-
when Hash
|
344
|
+
case
|
345
|
+
when object.class <= Hash
|
347
346
|
object.each { |k, v| @children[k] = TreeHash.new(v, self) }
|
348
|
-
when Array
|
347
|
+
when object.class <= Array
|
349
348
|
object.each_with_index { |a, i| @children[i] = TreeHash.new(a, self) }
|
350
349
|
else
|
351
350
|
@children = object
|
@@ -353,7 +352,13 @@ class TreeHash
|
|
353
352
|
end
|
354
353
|
|
355
354
|
def add_child(key, child)
|
356
|
-
|
355
|
+
if Array >= node_class && !key.is_a?(Integer)
|
356
|
+
# If the class was an Array but a hash key was passed we need to replace this
|
357
|
+
# node entirely
|
358
|
+
replace_with(key => child)
|
359
|
+
else
|
360
|
+
@children[key] = TreeHash.new(child, self)
|
361
|
+
end
|
357
362
|
end
|
358
363
|
|
359
364
|
def process_bridge_part(part)
|
@@ -250,9 +250,13 @@ module BBLib
|
|
250
250
|
opts[:default] = [] unless opts.include?(:default) || opts.include?(:default_proc)
|
251
251
|
methods.each do |method|
|
252
252
|
attr_custom(method, opts) do |arg|
|
253
|
-
|
254
|
-
|
255
|
-
|
253
|
+
if opts[:allow_nil] && arg.nil?
|
254
|
+
arg
|
255
|
+
else
|
256
|
+
args = arg.is_a?(Array) ? arg : [arg]
|
257
|
+
args = args.uniq if opts[:uniq]
|
258
|
+
args
|
259
|
+
end
|
256
260
|
end
|
257
261
|
attr_array_adder(method, opts[:adder_name], singleton: opts[:singleton]) if opts[:add_rem] || opts[:adder]
|
258
262
|
attr_array_remover(method, opts[:remover_name], singleton: opts[:singleton]) if opts[:add_rem] || opts[:remover]
|
@@ -6,8 +6,8 @@ module BBLib
|
|
6
6
|
|
7
7
|
def bridge_method(*class_methods)
|
8
8
|
class_methods.each do |class_method|
|
9
|
-
define_method(class_method) do |*args|
|
10
|
-
self.class.send(class_method, *args)
|
9
|
+
define_method(class_method) do |*args, &block|
|
10
|
+
self.class.send(class_method, *args, &block)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
true
|
@@ -5,12 +5,11 @@ module BBLib
|
|
5
5
|
module Hooks
|
6
6
|
|
7
7
|
[:before, :after].each do |hook_type|
|
8
|
-
define_method(hook_type) do |*methods, **opts|
|
9
|
-
raise ArgumentError, 'You must pass in at least one method followed by the name of the hook method.' if methods.size < 2
|
10
|
-
hooks = _hooks[hook_type][methods.
|
11
|
-
hooks[:methods] += methods
|
8
|
+
define_method(hook_type) do |*methods, **opts, &block|
|
9
|
+
raise ArgumentError, 'You must pass in at least one method followed by the name of the hook method or a block.' if methods.size < 2 && block.nil?
|
10
|
+
hooks = _hooks[hook_type][methods.last] ||= { methods: methods[0..-2], opts: { block: block } }
|
12
11
|
hooks[:opts] = hooks[:opts].deep_merge(opts)
|
13
|
-
methods.each { |method| _hook_method(method) if method_defined?(method) }
|
12
|
+
methods[0..(block ? -1 : -2)].each { |method| _hook_method(method) if method_defined?(method) }
|
14
13
|
true
|
15
14
|
end
|
16
15
|
end
|
@@ -34,8 +33,9 @@ module BBLib
|
|
34
33
|
def _hook_method(method, force: false)
|
35
34
|
return false if _defining_hook?
|
36
35
|
[:before, :after].each do |hook_type|
|
37
|
-
_hooks[hook_type].find_all { |hook, data| data[:methods].include?(method) }.to_h.each do |hook, data|
|
38
|
-
|
36
|
+
_hooks[hook_type].find_all { |hook, data| data[:methods].include?(method) || data[:opts][:block] && hook == method }.to_h.each do |hook, data|
|
37
|
+
hook = data[:opts][:block] if data[:opts][:block]
|
38
|
+
next if !force && _hooked_methods[hook_type] && _hooked_methods[hook_type][hook.is_a?(Proc) ? hook.object_id : hook] && _hooked_methods[hook_type][hook.is_a?(Proc) ? hook.object_id : hook].include?(method)
|
39
39
|
send("_hook_#{hook_type}_method", method, hook, data[:opts])
|
40
40
|
end
|
41
41
|
end
|
@@ -69,6 +69,7 @@ module BBLib
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def _add_hooked_method(type, hook, method)
|
72
|
+
hook = hook.object_id if hook.is_a?(Proc)
|
72
73
|
history = _hooked_methods[type]
|
73
74
|
history[hook] = {} unless history[hook]
|
74
75
|
history[hook][method] = instance_method(method)
|
@@ -96,11 +97,11 @@ module BBLib
|
|
96
97
|
margs = args
|
97
98
|
margs = [method] + args if opts[:send_method]
|
98
99
|
margs = args + [opts[:add_args]].flatten(1) if opts[:add_args]
|
99
|
-
result = method(hook).call(*margs)
|
100
|
+
result = (hook.is_a?(Proc) ? hook : method(hook)).call(*margs)
|
100
101
|
return result if result && opts[:try_first]
|
101
102
|
args = result if opts[:modify_args]
|
102
103
|
else
|
103
|
-
method(hook).call
|
104
|
+
hook.is_a?(Proc) ? hook.call : method(hook).call
|
104
105
|
end
|
105
106
|
original.bind(self).call(*args, &block)
|
106
107
|
end
|
@@ -125,17 +126,17 @@ module BBLib
|
|
125
126
|
define_method(method) do |*args, &block|
|
126
127
|
rtr = original.bind(self).call(*args, &block)
|
127
128
|
if opts[:send_args]
|
128
|
-
method(hook).call(*args)
|
129
|
+
(hook.is_a?(Proc) ? hook : method(hook)).call(*args)
|
129
130
|
elsif opts[:send_return] || opts[:send_value]
|
130
|
-
result = method(hook).call(rtr)
|
131
|
+
result = (hook.is_a?(Proc) ? hook : method(hook)).call(rtr)
|
131
132
|
rtr = result if opts[:modify_value] || opts[:modify_return]
|
132
133
|
elsif opts[:send_return_ary] || opts[:send_value_ary]
|
133
|
-
result = method(hook).call(*rtr)
|
134
|
+
result = (hook.is_a?(Proc) ? hook : method(hook)).call(*rtr)
|
134
135
|
rtr = result if opts[:modify_value] || opts[:modify_return]
|
135
136
|
elsif opts[:send_all]
|
136
|
-
result = method(hook).call(args: args, value: rtr, method: method)
|
137
|
+
result = (hook.is_a?(Proc) ? hook : method(hook)).call(args: args, value: rtr, method: method)
|
137
138
|
else
|
138
|
-
method(hook).call
|
139
|
+
(hook.is_a?(Proc) ? hook : method(hook)).call
|
139
140
|
end
|
140
141
|
rtr
|
141
142
|
end
|
@@ -2,7 +2,7 @@ module BBLib
|
|
2
2
|
def self.title_case(str, first_only: true)
|
3
3
|
str = str.to_s unless str.is_a?(String)
|
4
4
|
ignoreables = %w(a an the on upon and but or in with to)
|
5
|
-
regx = /\s+|\-|\_|(?<=\W|^)\"(?=\w|$)|(?<=\W|^)\'(?=\w|$)|\(|\)|\[|\]|\{|\}|\#/
|
5
|
+
regx = /\s+|\-|\_|(?<=[\w\d])\.(?=[\w\d])|(?<=\W|^)\"(?=\w|$)|(?<=\W|^)\'(?=\w|$)|\(|\)|\[|\]|\{|\}|\#/
|
6
6
|
spacing = str.scan(regx).to_a
|
7
7
|
words = str.split(regx).map do |word|
|
8
8
|
if ignoreables.include?(word.downcase)
|
@@ -15,7 +15,9 @@ module BBLib
|
|
15
15
|
end
|
16
16
|
# Always cap the first word
|
17
17
|
words[0] = words.first.to_s.slice(0,1).to_s.upcase + words.first.to_s[1..-1].to_s
|
18
|
-
words.interleave(spacing).join
|
18
|
+
combined = words.interleave(spacing).join
|
19
|
+
combined.scan(/(?<=\.)\w(?=\.)/).each { |part| combined.sub!(".#{part}.", ".#{part}.".upcase) }
|
20
|
+
combined
|
19
21
|
end
|
20
22
|
|
21
23
|
def self.start_case(str, first_only: false)
|
data/lib/bblib/core/util/file.rb
CHANGED
@@ -135,6 +135,16 @@ class Numeric
|
|
135
135
|
def to_file_size(*args)
|
136
136
|
BBLib.to_file_size(self, *args)
|
137
137
|
end
|
138
|
+
|
139
|
+
BBLib::FILE_SIZES.each do |name, data|
|
140
|
+
define_method(name) do
|
141
|
+
self * data[:mult]
|
142
|
+
end
|
143
|
+
|
144
|
+
define_method(name.pluralize) do
|
145
|
+
self * data[:mult]
|
146
|
+
end
|
147
|
+
end
|
138
148
|
end
|
139
149
|
|
140
150
|
# Monkey patches for the String class
|
data/lib/bblib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bblib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Black
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- lib/bblib/cli/options/untoggle.rb
|
112
112
|
- lib/bblib/cli/opts_parser.rb
|
113
113
|
- lib/bblib/cli/util.rb
|
114
|
+
- lib/bblib/color.rb
|
114
115
|
- lib/bblib/core.rb
|
115
116
|
- lib/bblib/core/classes/hash_struct.rb
|
116
117
|
- lib/bblib/core/classes/splitter.rb
|
@@ -177,8 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
177
178
|
- !ruby/object:Gem::Version
|
178
179
|
version: '0'
|
179
180
|
requirements: []
|
180
|
-
|
181
|
-
rubygems_version: 2.7.3
|
181
|
+
rubygems_version: 3.0.2
|
182
182
|
signing_key:
|
183
183
|
specification_version: 4
|
184
184
|
summary: A library containing many reusable, basic functions.
|