monkey_patches 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/monkey_patches.rb +5 -0
- data/lib/monkey_patches/Logger.rb +44 -0
- data/lib/monkey_patches/array.rb +6 -0
- data/lib/monkey_patches/hash.rb +11 -0
- data/lib/monkey_patches/math.rb +27 -0
- data/lib/monkey_patches/module.rb +21 -0
- data/lib/monkey_patches/version.rb +3 -0
- data/monkey_patches.gemspec +23 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 14d05c1b36f28d246a851711661d41d383ea1943
|
4
|
+
data.tar.gz: c2a3ea8288352a3a0988ed18addd2cb035a34a24
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 39b7c4e513b5789fddf17caa180269ff14a5a79123d1a7532e77892f1f3a904f1fe10f6572f3b65dd84ac45a4ab24f3c80f0add0714409a76f0c2d03db4e0638
|
7
|
+
data.tar.gz: 8d060b3b640a52e844253c521c44f55b1dffd9dfd51b47a14a4d1326a906ef854d24839335c280d18e78a40f6fa7e31c8602fc43cb2ff698a559bdac6ff51327
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Javier L. Velasquez
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# MonkeyPatches
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'monkey_patches'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install monkey_patches
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( http://github.com/<my-github-username>/monkey_patches/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
# Original Code for this module can be found here
|
4
|
+
# http://stackoverflow.com/questions/917566/ruby-share-logger-instance-among-module-classes
|
5
|
+
module Logging
|
6
|
+
|
7
|
+
def logger
|
8
|
+
@logger ||= Logging.logger_for(self.class.name)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Use a hash class-ivar to cache a unique Logger per class:
|
12
|
+
@loggers = {}
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def logger_for(classname)
|
16
|
+
@loggers[classname] ||= configure_logger_for(classname)
|
17
|
+
end
|
18
|
+
|
19
|
+
def configure_logger_for(classname)
|
20
|
+
logger = Logger.new(STDOUT)
|
21
|
+
logger.progname = classname
|
22
|
+
logger
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Turn off debugging. Will now only display errors and fatal messages.
|
27
|
+
def turn_off_debugging
|
28
|
+
logger.level = Logger::ERROR
|
29
|
+
end
|
30
|
+
|
31
|
+
# Turn on debugging
|
32
|
+
def turn_on_debugging
|
33
|
+
logger.level = Logger::DEBUG
|
34
|
+
end
|
35
|
+
|
36
|
+
def debugging_enabled?
|
37
|
+
if logger.level == Logger::DEBUG
|
38
|
+
return true
|
39
|
+
else
|
40
|
+
return false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Math
|
2
|
+
# Performs a logarithmic sleep based on a set of integers or up to an input integer
|
3
|
+
def Math.natural_logarithmic_sleep(set, constant_multiplier=1, stepping_factor=1, debugging=false)
|
4
|
+
require 'Logger'
|
5
|
+
logger = Logger.new(STDOUT)
|
6
|
+
logger.level = Logger::DEBUG
|
7
|
+
|
8
|
+
total_sleep_time = 0
|
9
|
+
if !set.is_a? Array and !set.is_a? Range
|
10
|
+
set = (1 .. set)
|
11
|
+
end
|
12
|
+
|
13
|
+
logger.debug("Constant multiplier for logarithmic scale is set to #{constant_multiplier}") if debugging
|
14
|
+
logger.debug("Stepping factor is #{stepping_factor}") if stepping_factor > 1 and stepping_factor != set.size and debugging
|
15
|
+
|
16
|
+
set.step(stepping_factor) do |iteration|
|
17
|
+
logarithm = Math.log iteration
|
18
|
+
sleep_time = logarithm * constant_multiplier
|
19
|
+
logger.debug("Iteration #{iteration} sleeping for #{sleep_time} seconds (zZz)") if debugging
|
20
|
+
yield sleep_time, iteration, stepping_factor
|
21
|
+
sleep(sleep_time) unless debugging
|
22
|
+
total_sleep_time += sleep_time
|
23
|
+
|
24
|
+
end
|
25
|
+
logger.debug("Slept for #{total_sleep_time} seconds (zZzZz)") if debugging
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Module
|
2
|
+
def self.resolve_class_ignore_plurality(class_name)
|
3
|
+
class_name = ActiveSupport::Inflector.singularize(class_name.split('_').map(&:capitalize).join(''))
|
4
|
+
if class_exists?(class_name) then
|
5
|
+
Kernel.const_get(class_name)
|
6
|
+
else
|
7
|
+
if class_exists?(class_name[0, (class_name.size - 1)]) then
|
8
|
+
Kernel.const_get(class_name[0, (class_name.size - 1)])
|
9
|
+
else
|
10
|
+
nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.class_exists?(class_name)
|
16
|
+
klass = Module.const_get(class_name)
|
17
|
+
return klass.is_a?(Class)
|
18
|
+
rescue NameError
|
19
|
+
return false
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'monkey_patches/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'monkey_patches'
|
8
|
+
spec.version = MonkeyPatches::VERSION
|
9
|
+
spec.authors = ['Javier L. Velasquez']
|
10
|
+
spec.email = ['nycjv321@gmail.com']
|
11
|
+
spec.summary = 'Monkey patches for standard libs'
|
12
|
+
spec.description = 'Provides new functionality to some standard classes'
|
13
|
+
spec.homepage = ''
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: monkey_patches
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Javier L. Velasquez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Provides new functionality to some standard classes
|
42
|
+
email:
|
43
|
+
- nycjv321@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/monkey_patches.rb
|
54
|
+
- lib/monkey_patches/Logger.rb
|
55
|
+
- lib/monkey_patches/array.rb
|
56
|
+
- lib/monkey_patches/hash.rb
|
57
|
+
- lib/monkey_patches/math.rb
|
58
|
+
- lib/monkey_patches/module.rb
|
59
|
+
- lib/monkey_patches/version.rb
|
60
|
+
- monkey_patches.gemspec
|
61
|
+
homepage: ''
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.4.5
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Monkey patches for standard libs
|
85
|
+
test_files: []
|