golly-utils 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/.rspec +8 -0
- data/.simplecov +14 -0
- data/.travis.yml +5 -0
- data/.yardopts +6 -0
- data/CHANGELOG.md +10 -0
- data/Gemfile +12 -0
- data/Gemfile.corvid +27 -0
- data/Gemfile.lock +86 -0
- data/Guardfile +44 -0
- data/README.md +3 -0
- data/RELEASE.md +13 -0
- data/Rakefile +6 -0
- data/bin/guard +16 -0
- data/bin/rake +16 -0
- data/bin/rspec +16 -0
- data/bin/yard +16 -0
- data/bin/yardoc +16 -0
- data/bin/yri +16 -0
- data/golly-utils.gemspec +17 -0
- data/lib/golly-utils/attr_declarative.rb +74 -0
- data/lib/golly-utils/callbacks.rb +92 -0
- data/lib/golly-utils/child_process.rb +124 -0
- data/lib/golly-utils/colourer.rb +50 -0
- data/lib/golly-utils/delegator.rb +81 -0
- data/lib/golly-utils/multi_io.rb +13 -0
- data/lib/golly-utils/ruby_ext.rb +2 -0
- data/lib/golly-utils/ruby_ext/array_to_hash.rb +29 -0
- data/lib/golly-utils/ruby_ext/deep_dup.rb +33 -0
- data/lib/golly-utils/ruby_ext/env_helpers.rb +27 -0
- data/lib/golly-utils/ruby_ext/hash_combinations.rb +49 -0
- data/lib/golly-utils/ruby_ext/pretty_error_messages.rb +9 -0
- data/lib/golly-utils/ruby_ext/subclasses.rb +17 -0
- data/lib/golly-utils/test/spec/deferrable_specs.rb +85 -0
- data/lib/golly-utils/test/spec/within_time.rb +56 -0
- data/lib/golly-utils/version.rb +3 -0
- data/test/bootstrap/all.rb +4 -0
- data/test/bootstrap/spec.rb +5 -0
- data/test/bootstrap/unit.rb +4 -0
- data/test/spec/child_process_mock_target.rb +28 -0
- data/test/spec/child_process_spec.rb +41 -0
- data/test/unit/attr_declarative_test.rb +54 -0
- data/test/unit/callbacks_test.rb +76 -0
- data/test/unit/delegator_test.rb +99 -0
- data/test/unit/multi_io_test.rb +18 -0
- data/test/unit/ruby_ext/env_helpers_test.rb +48 -0
- data/test/unit/ruby_ext/hash_combinations_test.rb +31 -0
- data/test/unit/ruby_ext/subclasses_test.rb +24 -0
- metadata +107 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.simplecov
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
SimpleCov.start do
|
2
|
+
# project_name 'My Awesome Project'
|
3
|
+
|
4
|
+
# add_group 'Models', 'app/model'
|
5
|
+
# add_group 'Plugins', '(app|lib)/plugins'
|
6
|
+
|
7
|
+
# Remove test code from coverage
|
8
|
+
add_filter 'test'
|
9
|
+
|
10
|
+
# Add files that don't get required to coverage too
|
11
|
+
add_files_to_coverage_at_exit '{app,lib}/**/*.rb'
|
12
|
+
end
|
13
|
+
|
14
|
+
# vim:ft=ruby et ts=2 sw=2:
|
data/.travis.yml
ADDED
data/.yardopts
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.corvid
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# This file is generated by corvid update:deps
|
2
|
+
|
3
|
+
gem "corvid", git: 'git://github.com/japgolly/corvid.git'
|
4
|
+
#gem "corvid", path: "/home/golly/projects/corvid"
|
5
|
+
#gem "corvid", ">= 0.0.1"
|
6
|
+
group :debug do
|
7
|
+
gem "debugger", platforms: :mri
|
8
|
+
end
|
9
|
+
group :doc do
|
10
|
+
gem "yard"
|
11
|
+
end
|
12
|
+
group :rake do
|
13
|
+
gem "rake"
|
14
|
+
end
|
15
|
+
group :test do
|
16
|
+
gem "ci_reporter", require: false
|
17
|
+
gem "simplecov", ">= 0.6.4", require: false
|
18
|
+
end
|
19
|
+
group :test_spec do
|
20
|
+
gem "guard-rspec", require: false
|
21
|
+
gem "rspec"
|
22
|
+
end
|
23
|
+
group :test_unit do
|
24
|
+
gem "guard-minitest", ">= 0.5.0", require: false
|
25
|
+
gem "minitest"
|
26
|
+
gem "turn"
|
27
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/japgolly/corvid.git
|
3
|
+
revision: b4bd43588c25b3496c703f5b31a212f35d887de9
|
4
|
+
specs:
|
5
|
+
corvid (0.0.1)
|
6
|
+
|
7
|
+
PATH
|
8
|
+
remote: .
|
9
|
+
specs:
|
10
|
+
golly-utils (0.0.1)
|
11
|
+
|
12
|
+
GEM
|
13
|
+
remote: http://rubygems.org/
|
14
|
+
specs:
|
15
|
+
ansi (1.4.3)
|
16
|
+
builder (3.0.0)
|
17
|
+
ci_reporter (1.7.0)
|
18
|
+
builder (>= 2.1.2)
|
19
|
+
columnize (0.3.6)
|
20
|
+
debugger (1.1.4)
|
21
|
+
columnize (>= 0.3.1)
|
22
|
+
debugger-linecache (~> 1.1.1)
|
23
|
+
debugger-ruby_core_source (~> 1.1.3)
|
24
|
+
debugger-linecache (1.1.2)
|
25
|
+
debugger-ruby_core_source (>= 1.1.1)
|
26
|
+
debugger-ruby_core_source (1.1.3)
|
27
|
+
diff-lcs (1.1.3)
|
28
|
+
ffi (1.0.11)
|
29
|
+
ffi (1.0.11-java)
|
30
|
+
guard (1.2.3)
|
31
|
+
listen (>= 0.4.2)
|
32
|
+
thor (>= 0.14.6)
|
33
|
+
guard-minitest (0.5.0)
|
34
|
+
guard (>= 0.4)
|
35
|
+
guard-rspec (1.1.0)
|
36
|
+
guard (>= 1.1)
|
37
|
+
kramdown (0.13.7)
|
38
|
+
listen (0.4.7)
|
39
|
+
rb-fchange (~> 0.0.5)
|
40
|
+
rb-fsevent (~> 0.9.1)
|
41
|
+
rb-inotify (~> 0.8.8)
|
42
|
+
minitest (3.2.0)
|
43
|
+
multi_json (1.3.6)
|
44
|
+
rake (0.9.2.2)
|
45
|
+
rb-fchange (0.0.5)
|
46
|
+
ffi
|
47
|
+
rb-fsevent (0.9.1)
|
48
|
+
rb-inotify (0.8.8)
|
49
|
+
ffi (>= 0.5.0)
|
50
|
+
rdiscount (1.6.8)
|
51
|
+
rspec (2.10.0)
|
52
|
+
rspec-core (~> 2.10.0)
|
53
|
+
rspec-expectations (~> 2.10.0)
|
54
|
+
rspec-mocks (~> 2.10.0)
|
55
|
+
rspec-core (2.10.1)
|
56
|
+
rspec-expectations (2.10.0)
|
57
|
+
diff-lcs (~> 1.1.3)
|
58
|
+
rspec-mocks (2.10.1)
|
59
|
+
simplecov (0.6.4)
|
60
|
+
multi_json (~> 1.0)
|
61
|
+
simplecov-html (~> 0.5.3)
|
62
|
+
simplecov-html (0.5.3)
|
63
|
+
thor (0.15.4)
|
64
|
+
turn (0.9.6)
|
65
|
+
ansi
|
66
|
+
yard (0.8.2.1)
|
67
|
+
|
68
|
+
PLATFORMS
|
69
|
+
java
|
70
|
+
ruby
|
71
|
+
|
72
|
+
DEPENDENCIES
|
73
|
+
ci_reporter
|
74
|
+
corvid!
|
75
|
+
debugger
|
76
|
+
golly-utils!
|
77
|
+
guard-minitest (>= 0.5.0)
|
78
|
+
guard-rspec
|
79
|
+
kramdown
|
80
|
+
minitest
|
81
|
+
rake
|
82
|
+
rdiscount
|
83
|
+
rspec
|
84
|
+
simplecov (>= 0.6.4)
|
85
|
+
turn
|
86
|
+
yard
|
data/Guardfile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'corvid/guard'
|
2
|
+
|
3
|
+
########################################################################################################################
|
4
|
+
# test/unit
|
5
|
+
|
6
|
+
group :unit do
|
7
|
+
guard 'minitest', test_folders: 'test/unit', test_file_patterns: '*_test.rb' do
|
8
|
+
|
9
|
+
# Src files
|
10
|
+
watch(%r'^lib/golly-utils/(.+)\.rb$') {|m| "test/unit/#{m[1]}_test.rb"}
|
11
|
+
|
12
|
+
# Each test
|
13
|
+
watch(%r'^test/unit/.+_test\.rb$')
|
14
|
+
|
15
|
+
if bulk?
|
16
|
+
# Test stuff affecting everything
|
17
|
+
watch(%r'^test/bootstrap/(?:all|unit).rb') {"test/unit"}
|
18
|
+
watch(%r'^test/helpers/.+$') {"test/unit"}
|
19
|
+
watch(%r'^test/factories/.+$') {"test/unit"}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end if Dir.exists?('test/unit')
|
23
|
+
|
24
|
+
########################################################################################################################
|
25
|
+
# test/spec
|
26
|
+
|
27
|
+
rspec_options= read_rspec_options(File.dirname __FILE__)
|
28
|
+
group :spec do
|
29
|
+
guard 'rspec', binstubs: true, spec_paths: ['test/spec'], cli: rspec_options, all_on_start: false, all_after_pass: false do
|
30
|
+
|
31
|
+
# Src files
|
32
|
+
watch(%r'^lib/(.+)\.rb$') {|m| "test/spec/#{m[1]}_spec.rb"}
|
33
|
+
|
34
|
+
# Each spec
|
35
|
+
watch(%r'^test/spec/.+_spec\.rb$')
|
36
|
+
|
37
|
+
if bulk?
|
38
|
+
# Test stuff affecting everything
|
39
|
+
watch(%r'^test/bootstrap/(?:all|spec).rb') {"test/spec"}
|
40
|
+
watch(%r'^test/helpers/.+$') {"test/spec"}
|
41
|
+
watch(%r'^test/factories/.+$') {"test/spec"}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end if Dir.exists?('test/spec')
|
data/README.md
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
[![Build Status](https://secure.travis-ci.org/japgolly/golly-utils.png?branch=master)](http://travis-ci.org/japgolly/golly-utils)
|
2
|
+
[![Dependency Status](https://gemnasium.com/japgolly/golly-utils.png)](https://gemnasium.com/japgolly/golly-utils)
|
3
|
+
[![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/japgolly/golly-utils)
|
data/RELEASE.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
To install locally:
|
2
|
+
gem build golly-utils.gemspec
|
3
|
+
gem install golly-utils-x.x.x.gem
|
4
|
+
|
5
|
+
To perform a release:
|
6
|
+
* Update `CHANGELOG.md`
|
7
|
+
* `bundle exec rake test`
|
8
|
+
* Ensure no uncommitted changes.
|
9
|
+
* `gem build golly-utils.gemspec`
|
10
|
+
* `gem push golly-utils-x.x.x.gem`
|
11
|
+
* Update `version.rb`
|
12
|
+
* Commit
|
13
|
+
|
data/Rakefile
ADDED
data/bin/guard
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'guard' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('guard', 'guard')
|
data/bin/rake
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'rake' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('rake', 'rake')
|
data/bin/rspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'rspec' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('rspec-core', 'rspec')
|
data/bin/yard
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'yard' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('yard', 'yard')
|
data/bin/yardoc
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'yardoc' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('yard', 'yardoc')
|
data/bin/yri
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'yri' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('yard', 'yri')
|
data/golly-utils.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path('../lib/golly-utils/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "golly-utils"
|
6
|
+
gem.version = GollyUtils::VERSION
|
7
|
+
gem.date = Date.today.to_s
|
8
|
+
gem.summary = %q{Golly's Utils: Reusable Ruby utility code.}
|
9
|
+
gem.description = %q{This contains a bunch of shared, utility code that has no external dependencies apart from Ruby stdlib.}
|
10
|
+
gem.authors = ["David Barri"]
|
11
|
+
gem.email = ["japgolly@gmail.com"]
|
12
|
+
gem.homepage = "https://github.com/japgolly/golly-utils"
|
13
|
+
|
14
|
+
gem.files = File.exists?('.git') ? `git ls-files`.split($\) : Dir['*']
|
15
|
+
gem.require_paths = %w[lib]
|
16
|
+
gem.test_files = gem.files.grep(/^test\//)
|
17
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module GollyUtils
|
2
|
+
module AttrDeclarative
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.send :include, InstanceMethods
|
6
|
+
base.send :include, InstanceAndClassMethods
|
7
|
+
base.extend InstanceAndClassMethods
|
8
|
+
base.extend ClassMethods
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def self.get_default(key, clazz)
|
14
|
+
while clazz
|
15
|
+
if clazz.instance_variables.include?(key)
|
16
|
+
return clazz.instance_variable_get(key)
|
17
|
+
end
|
18
|
+
clazz= clazz.superclass
|
19
|
+
end
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
|
23
|
+
#-------------------------------------------------------------------------------------------------------------------
|
24
|
+
|
25
|
+
# TODO default should be default_value/default_proc
|
26
|
+
# TODO add an option to specify whether proc should be eval'd everytime or once and return value cached
|
27
|
+
|
28
|
+
module ClassMethods
|
29
|
+
def attr_declarative(first,*args)
|
30
|
+
names= ([first] + args).flatten.uniq
|
31
|
+
options= names.last.is_a?(Hash) ? names.pop.clone : {}
|
32
|
+
default= options.delete :default
|
33
|
+
raise "Unknown options: #{options.keys}" unless options.empty?
|
34
|
+
names.each do |name|
|
35
|
+
dvar= "@_#{name}_default"
|
36
|
+
class_eval <<-EOB
|
37
|
+
|
38
|
+
def #{name}
|
39
|
+
if block_given?
|
40
|
+
@#{name}= yield
|
41
|
+
elsif not @#{name}.nil?
|
42
|
+
@#{name}
|
43
|
+
elsif d= ::GollyUtils::AttrDeclarative.get_default(:#{dvar}, self.class)
|
44
|
+
@#{name}= d.call
|
45
|
+
else
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.#{name}(&block)
|
51
|
+
instance_variable_set :#{dvar}, block
|
52
|
+
end
|
53
|
+
|
54
|
+
EOB
|
55
|
+
instance_variable_set dvar.to_sym, lambda{ default } unless default.nil?
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
#{default.nil? ? '' : "instance_variable_set :#{dvar}, block
|
60
|
+
#{default.nil? ? 'nil' : "@#{name}= (#{default.inspect})"}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
#-------------------------------------------------------------------------------------------------------------------
|
65
|
+
|
66
|
+
module InstanceAndClassMethods
|
67
|
+
end
|
68
|
+
|
69
|
+
#-------------------------------------------------------------------------------------------------------------------
|
70
|
+
|
71
|
+
module InstanceMethods
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|