quality_extensions 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Readme +3 -5
- data/lib/quality_extensions/chainable_safe_nil.rb +173 -0
- data/lib/quality_extensions/hash/delete_unless.rb +41 -0
- data/lib/quality_extensions/hash/hash_select.rb +45 -0
- data/lib/quality_extensions/safe_nil.rb +142 -0
- metadata +77 -74
- data/lib/quality_extensions/kernel/autoreload.rb +0 -128
data/Readme
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
=
|
1
|
+
= Quality Ruby Extensions
|
2
2
|
|
3
|
-
[<b>Home page</b>:] http://
|
4
|
-
[<b>Project site</b>:] http://rubyforge.org/projects/
|
3
|
+
[<b>Home page</b>:] http://quality-ext.rubyforge.org/
|
4
|
+
[<b>Project site</b>:] http://rubyforge.org/projects/quality-ext/
|
5
5
|
[<b>Gem install</b>:] <tt>gem install quality_extensions</tt>
|
6
6
|
[<b>License</b>:] {Ruby License}[link:files/License.html]
|
7
7
|
|
@@ -50,5 +50,3 @@ Tests are self-contained within the file for the code that is under test.
|
|
50
50
|
To run the tests directly, you need to use the <tt>exrb</tt> command that is part of the {Ratchets}[http://ratchets.rubyforge.org/] project.
|
51
51
|
|
52
52
|
At some point in time, we may extract them into separate files using the Exacto test extractor tool.
|
53
|
-
|
54
|
-
<b>QualitySmith developers</b>: If you use <tt>vim</tt>, you can set up your editor to run the tests just by typing the <tt>:Test</tt> command. To set that up, just include <tt>~/svn/devscripts/vim/include.vim</tt> .
|
@@ -0,0 +1,173 @@
|
|
1
|
+
#--
|
2
|
+
# Credits::
|
3
|
+
# * Daniel Lucraft (http://www.daniellucraft.com/blog/2007/08/null-objects/) -- for the idea
|
4
|
+
# * Tyler Rick -- packaged it, added some documention, and added some tests, realized it didn't work as well as one might hope...
|
5
|
+
# Copyright:: ?
|
6
|
+
# License:: ?
|
7
|
+
# Submit to Facets?:: No
|
8
|
+
# Developer notes::
|
9
|
+
#++
|
10
|
+
|
11
|
+
# The __? method just returns the object itself for all objects except for nil. For nil, __? will return a special version of nil that lets you call undefined
|
12
|
+
# methods.
|
13
|
+
#
|
14
|
+
# If you call an undefined method on nil._?, you will get back an instance of ChainableSafeNil -- rather than raising an exception, which is what would
|
15
|
+
# happen if you called the same method on a _plain_ old nil.
|
16
|
+
#
|
17
|
+
# __? gives us a much conciser alternative to this common pattern:
|
18
|
+
# might_be_nil ? might_be_nil.some_method : nil
|
19
|
+
# or
|
20
|
+
# (might_be_nil && might_be_nil.some_method)
|
21
|
+
#
|
22
|
+
# ... where might_be_nil is something that you hope is not nil most of the time, but which may on accosion be nil (and when it is, you don't want an exception
|
23
|
+
# to be raised!).
|
24
|
+
#
|
25
|
+
# For example, accessing a key from a hash:
|
26
|
+
# (hash[:a] && hash[:a][:b] && hash[:a][:b].some_method)
|
27
|
+
#
|
28
|
+
# With __?, that simply becomes
|
29
|
+
# hash[:a].__?[:b].some_method)
|
30
|
+
#
|
31
|
+
# Unfortunately, this idea fails in two ways:
|
32
|
+
# * nil.__?.whatever will return an instance of ChainableSafeNil, which means you may end up with ChainableSafeNil objects as values of variables and arguments
|
33
|
+
# in your code... which seems messy, undesirable, and undefined (Should ChainableSafeNil act like nil? Should it evaluate to false like nil does? Good luck
|
34
|
+
# with that...)
|
35
|
+
# * If something evaluates to nil further on down the chain, after the __?, then all method calls to that nil will be unsafe. For example:
|
36
|
+
# hash = { :a => {} }
|
37
|
+
# hash[:a].__?[:b][:c]) => NoMethodError
|
38
|
+
#
|
39
|
+
# Conclusion: Chaining is impossible -- Just use _? on any object that might return nil (on which you want to call a method).
|
40
|
+
|
41
|
+
|
42
|
+
require 'singleton'
|
43
|
+
require 'rubygems'
|
44
|
+
require 'facets/more/basicobject'
|
45
|
+
|
46
|
+
|
47
|
+
class Object
|
48
|
+
def __?
|
49
|
+
self
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class NilClass
|
54
|
+
def __?
|
55
|
+
ChainableSafeNil.instance
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class C < BasicObject
|
60
|
+
end
|
61
|
+
|
62
|
+
class ChainableSafeNil < BasicObject
|
63
|
+
include Singleton
|
64
|
+
|
65
|
+
def inspect
|
66
|
+
"ChainableSafeNil"
|
67
|
+
end
|
68
|
+
|
69
|
+
def method_missing(method, *args, &block)
|
70
|
+
#puts "nil.respond_to?(method)=#{nil.respond_to?(method)}"
|
71
|
+
return ChainableSafeNil.instance unless nil.respond_to?(method)
|
72
|
+
nil.send(method, *args, &block) rescue ChainableSafeNil.instance
|
73
|
+
end
|
74
|
+
|
75
|
+
def ==(other)
|
76
|
+
#other.nil?
|
77
|
+
raise "Why on earth is this line never getting executed?? And yet if I remove this method entirely, equality breaks"
|
78
|
+
end
|
79
|
+
|
80
|
+
def nil?; true; end
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
# _____ _
|
86
|
+
# |_ _|__ ___| |_
|
87
|
+
# | |/ _ \/ __| __|
|
88
|
+
# | | __/\__ \ |_
|
89
|
+
# |_|\___||___/\__|
|
90
|
+
#
|
91
|
+
=begin test
|
92
|
+
require 'test/unit'
|
93
|
+
|
94
|
+
class TheTest < Test::Unit::TestCase
|
95
|
+
|
96
|
+
def test_simple__nil
|
97
|
+
hash = {}
|
98
|
+
assert_equal ChainableSafeNil.instance, hash[:a].__?.length
|
99
|
+
end
|
100
|
+
def test_simple__normal_objects
|
101
|
+
hash = {:a => 'abc'}
|
102
|
+
assert_equal 3, hash[:a].__?.length
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_chaining
|
106
|
+
hash = {}
|
107
|
+
|
108
|
+
assert_raise(NoMethodError) { hash[:a] .length * 4 }
|
109
|
+
assert_raise(NoMethodError) { hash[:a] [:b][:c] }
|
110
|
+
assert_raise(NoMethodError) { hash[:a] [:b][:c].some_method }
|
111
|
+
|
112
|
+
assert_equal ChainableSafeNil.instance, hash[:a].__?.length * 4
|
113
|
+
assert_equal ChainableSafeNil.instance, hash[:a].__?[:b][:c]
|
114
|
+
assert_equal ChainableSafeNil.instance, hash[:a].__?[:b][:c].some_method
|
115
|
+
|
116
|
+
# But it needs to be chainable even if the *receiver* of __? isn't nil but something *later* down the chain is nil...
|
117
|
+
# (in this example, hash[:a] isn't nil, but hash[:a][:b] is, making it unsafe to evaluate hash[:a][:b][:c])
|
118
|
+
hash = { :a => {} }
|
119
|
+
assert_raise(NoMethodError) { hash[:a] [:b] [:c] }
|
120
|
+
# Unfortunately, I don't know any way to make that possible!!!
|
121
|
+
assert_raise(NoMethodError) { hash[:a].__?[:b] [:c] }
|
122
|
+
# So one is left with calling __? for *anything* that might be nil...
|
123
|
+
assert_equal ChainableSafeNil.instance, hash[:a].__?[:b].__?[:c]
|
124
|
+
# ... which is what we were trying to avoid having to do! This means __? is *not* chainable and we may as well use the plain old _? / SafeNil.
|
125
|
+
# We have failed as programmers and may as well go home in shame.
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
def test_inspect
|
130
|
+
assert_equal 'ChainableSafeNil', nil.__?.inspect
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_nil?
|
134
|
+
assert ChainableSafeNil.instance.nil?
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_equality
|
138
|
+
assert_equal ChainableSafeNil.instance, ChainableSafeNil.instance
|
139
|
+
assert ChainableSafeNil.instance.eql?( nil.__?.length )
|
140
|
+
assert ChainableSafeNil.instance == nil.__?.length
|
141
|
+
|
142
|
+
assert ChainableSafeNil.instance == nil
|
143
|
+
# But:
|
144
|
+
assert nil != ChainableSafeNil.instance
|
145
|
+
|
146
|
+
# Why isn't this true?? Which == is getting called here?
|
147
|
+
#assert ChainableSafeNil.instance.send(:==, ChainableSafeNil.instance)
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_does_not_permanently_modify_nil_class
|
151
|
+
assert_raise(NoMethodError) { nil.foo }
|
152
|
+
nil.__?
|
153
|
+
assert_raise(NoMethodError) { nil.foo }
|
154
|
+
end
|
155
|
+
end
|
156
|
+
=end
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
# Alternative version #1:
|
161
|
+
# (See note in safe_nil.rb)
|
162
|
+
=begin
|
163
|
+
class NilClass
|
164
|
+
def __?
|
165
|
+
n = nil
|
166
|
+
def n.method_missing(*args)
|
167
|
+
__?
|
168
|
+
end
|
169
|
+
n
|
170
|
+
end
|
171
|
+
end
|
172
|
+
=end
|
173
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#--
|
2
|
+
# Author:: Tyler Rick
|
3
|
+
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
|
4
|
+
# License:: Ruby License
|
5
|
+
# Submit to Facets?:: Yes.
|
6
|
+
#++
|
7
|
+
|
8
|
+
require "rubygems"
|
9
|
+
|
10
|
+
class Hash
|
11
|
+
# call-seq:
|
12
|
+
# hash.delete_unless {| key, value | block } -> hash
|
13
|
+
#
|
14
|
+
# <tt>Hash#delete_unless</tt> is the opposite of <tt>Hash#delete_if</tt>: Deletes every key-value pair from <tt>hash</tt> _except_ those for which <tt>block</tt> evaluates to <tt>true</tt>.
|
15
|
+
#
|
16
|
+
def delete_unless(&block)
|
17
|
+
delete_if {|k, v|
|
18
|
+
!yield k, v
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# _____ _
|
24
|
+
# |_ _|__ ___| |_
|
25
|
+
# | |/ _ \/ __| __|
|
26
|
+
# | | __/\__ \ |_
|
27
|
+
# |_|\___||___/\__|
|
28
|
+
#
|
29
|
+
=begin test
|
30
|
+
require 'test/unit'
|
31
|
+
|
32
|
+
class TheTest < Test::Unit::TestCase
|
33
|
+
def test_1
|
34
|
+
hash_copy = hash = {:a => 1, :b => 2}
|
35
|
+
assert_equal hash.delete_if {|k,v| k != :b},
|
36
|
+
hash.delete_unless {|k,v| k == :b}
|
37
|
+
assert_equal({:b => 2}, hash)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
=end
|
41
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#--
|
2
|
+
# Author:: Tyler Rick
|
3
|
+
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
|
4
|
+
# License:: Ruby License
|
5
|
+
# Submit to Facets?:: Yes.
|
6
|
+
#++
|
7
|
+
|
8
|
+
require "rubygems"
|
9
|
+
|
10
|
+
class Hash
|
11
|
+
# call-seq:
|
12
|
+
# hash.hash_select {| key, value | block } -> hash
|
13
|
+
#
|
14
|
+
# <tt>Hash#reject</tt> returns a hash. One would intuitively expect <tt>Hash#select</tt> to also return a hash. However, it doesn't: instead, returns "a new array consisting of <tt>[key,value]</tt> pairs for which the block returns true".
|
15
|
+
#
|
16
|
+
# <tt>Hash#hash_select</tt> behaves how <tt>Hash#select</tt> (arguably) _should_ behave: Deletes every key-value pair from a copy of <tt>hash</tt> _except_ those for which <tt>block</tt> evaluates to <tt>true</tt>.
|
17
|
+
#
|
18
|
+
def hash_select(&block)
|
19
|
+
reject {|k, v|
|
20
|
+
!yield k, v
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
alias_method :hash_find_all, :hash_select
|
25
|
+
alias_method :delete_unless, :hash_select
|
26
|
+
end
|
27
|
+
|
28
|
+
# _____ _
|
29
|
+
# |_ _|__ ___| |_
|
30
|
+
# | |/ _ \/ __| __|
|
31
|
+
# | | __/\__ \ |_
|
32
|
+
# |_|\___||___/\__|
|
33
|
+
#
|
34
|
+
=begin test
|
35
|
+
require 'test/unit'
|
36
|
+
|
37
|
+
class TheTest < Test::Unit::TestCase
|
38
|
+
def test_1
|
39
|
+
hash_copy = hash = {:a => 1, :b => 2}
|
40
|
+
assert_equal hash.reject {|k,v| k != :b},
|
41
|
+
hash.hash_select {|k,v| k == :b}
|
42
|
+
assert_equal(hash_copy, hash)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
=end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
#--
|
2
|
+
# Credits::
|
3
|
+
# * Tom Locke (http://hobocentral.net/blog/2007/08/25/quiz/) -- original version
|
4
|
+
# * coderrr (http://coderrr.wordpress.com/2007/09/15/the-ternary-destroyer/) -- some optimizations
|
5
|
+
# * Tyler Rick -- packaged it, added some documention, and added some tests
|
6
|
+
# Copyright:: ?
|
7
|
+
# License:: ?
|
8
|
+
# Submit to Facets?:: Yes
|
9
|
+
# Developer notes::
|
10
|
+
#++
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
require 'singleton'
|
16
|
+
require 'rubygems'
|
17
|
+
require 'facets/more/basicobject'
|
18
|
+
|
19
|
+
|
20
|
+
class Object
|
21
|
+
def _?
|
22
|
+
self
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class NilClass
|
27
|
+
# The _? method just returns the object itself for all objects except for nil. For nil, _? will return a special version of nil (actually, an instance of
|
28
|
+
# SafeNil) that lets you call undefined methods.
|
29
|
+
#
|
30
|
+
# If you call an undefined method on nil._?, you will get back nil -- rather than raising an exception, which is what would happen if you called the same
|
31
|
+
# method on a _plain_ old nil!
|
32
|
+
#
|
33
|
+
# _? gives us a much conciser alternative to this common pattern:
|
34
|
+
# might_be_nil ? might_be_nil.some_method : nil
|
35
|
+
# or
|
36
|
+
# (might_be_nil && might_be_nil.some_method)
|
37
|
+
#
|
38
|
+
# ... where might_be_nil is something that you hope is not nil most of the time, but which may on accosion be nil (and when it is, you don't want an exception
|
39
|
+
# to be raised!).
|
40
|
+
#
|
41
|
+
# For example, accessing a key from a hash:
|
42
|
+
# (hash[:a] && hash[:a][:b] && hash[:a][:b].some_method)
|
43
|
+
#
|
44
|
+
# With _?, that simply becomes
|
45
|
+
# hash[:a]._?[:b]._?.some_method)
|
46
|
+
#
|
47
|
+
def _?
|
48
|
+
SafeNil.instance
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
# Extending BasicObject because it provides us with a clean slate. It is similar to Object except it has almost all the standard methods stripped away so that
|
54
|
+
# we will hit method_missing for almost all method routing.
|
55
|
+
class SafeNil < BasicObject
|
56
|
+
include Singleton # I assume this is because it's faster than instantiating a new object each time.
|
57
|
+
|
58
|
+
#undef inspect # Use nil's version of inspect... although I wonder whether it would be better to have it return "SafeNil" so you know it's different than a normal nil.
|
59
|
+
def inspect
|
60
|
+
'SafeNil'
|
61
|
+
end
|
62
|
+
|
63
|
+
def method_missing(method, *args, &block)
|
64
|
+
return nil unless nil.respond_to?(method) # A much faster alternative to 'rescue nil' that can be used most of the time to speed things up.
|
65
|
+
nil.send(method, *args, &block) rescue nil
|
66
|
+
end
|
67
|
+
|
68
|
+
def nil?; true; end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
# _____ _
|
76
|
+
# |_ _|__ ___| |_
|
77
|
+
# | |/ _ \/ __| __|
|
78
|
+
# | | __/\__ \ |_
|
79
|
+
# |_|\___||___/\__|
|
80
|
+
#
|
81
|
+
=begin test
|
82
|
+
require 'test/unit'
|
83
|
+
|
84
|
+
class TheTest < Test::Unit::TestCase
|
85
|
+
def test_simple__nil
|
86
|
+
hash = {}
|
87
|
+
assert_equal nil, hash[:a]._?.length
|
88
|
+
end
|
89
|
+
def test_simple__normal_objects
|
90
|
+
hash = {:a => 'abc'}
|
91
|
+
assert_equal 3, hash[:a]._?.length
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_chaining
|
95
|
+
hash = {}
|
96
|
+
assert_equal nil, hash[:a]._?.foo
|
97
|
+
assert_equal nil, hash[:a]._?[:b]._?[:c]
|
98
|
+
assert_equal nil, hash[:a]._?[:b]._?[:c]._?.some_method
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_inspect
|
102
|
+
assert_equal 'SafeNil', nil._?.inspect
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_nil?
|
106
|
+
assert SafeNil.instance.nil?
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_does_not_permanently_modify_nil_class
|
110
|
+
assert_raise(NoMethodError) { nil.foo }
|
111
|
+
nil._?
|
112
|
+
assert_raise(NoMethodError) { nil.foo }
|
113
|
+
end
|
114
|
+
end
|
115
|
+
=end
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
# Alternative version #1:
|
120
|
+
# This version is so nice and simple -- I wish we could use it...
|
121
|
+
# The problem with this implementation, however, is that it causes NilClass to be permanently modified with this new method_missing behavior.
|
122
|
+
# In other words, once you call _? once on nil, all instances of nil will forever behave the same as nil._? ! (So you may as well just modify NilClass
|
123
|
+
# directly.)
|
124
|
+
# This might have to do with the fact that nil itself is a “singleton object” (according to http://corelib.rubyonrails.org/classes/NilClass.html)
|
125
|
+
# Proof:
|
126
|
+
# puts nil.foo rescue p $! # => <NoMethodError: undefined method `foo' for nil:NilClass>
|
127
|
+
# nil._?
|
128
|
+
# puts nil.foo rescue p $! # => nil
|
129
|
+
# Too bad... it was so simple.
|
130
|
+
#
|
131
|
+
=begin
|
132
|
+
class NilClass
|
133
|
+
def _?
|
134
|
+
n = nil
|
135
|
+
def n.method_missing(*args)
|
136
|
+
nil
|
137
|
+
end
|
138
|
+
n
|
139
|
+
end
|
140
|
+
end
|
141
|
+
=end
|
142
|
+
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.4
|
3
3
|
specification_version: 1
|
4
4
|
name: quality_extensions
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.1.4
|
7
|
+
date: 2007-10-12 00:00:00 -07:00
|
8
8
|
summary: A collection of reusable Ruby methods.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -29,103 +29,106 @@ post_install_message:
|
|
29
29
|
authors:
|
30
30
|
- Tyler Rick and others
|
31
31
|
files:
|
32
|
-
- lib/quality_extensions/
|
33
|
-
- lib/quality_extensions/
|
34
|
-
- lib/quality_extensions/
|
35
|
-
- lib/quality_extensions/
|
36
|
-
- lib/quality_extensions/
|
32
|
+
- lib/quality_extensions/symbol/match.rb
|
33
|
+
- lib/quality_extensions/symbol/constantize.rb
|
34
|
+
- lib/quality_extensions/colored/toggleability.rb
|
35
|
+
- lib/quality_extensions/console/command.rb
|
36
|
+
- lib/quality_extensions/console/command.facets.1.8.51.rb
|
37
|
+
- lib/quality_extensions/console/command.facets.1.8.54.rb
|
38
|
+
- lib/quality_extensions/test/assert_includes.rb
|
37
39
|
- lib/quality_extensions/test/assert_anything.rb
|
38
|
-
- lib/quality_extensions/test/assert_exception.rb
|
39
40
|
- lib/quality_extensions/test/assert_user_error.rb
|
40
|
-
- lib/quality_extensions/test/
|
41
|
-
- lib/quality_extensions/test/difference_highlighting.rb
|
41
|
+
- lib/quality_extensions/test/assert_exception.rb
|
42
42
|
- lib/quality_extensions/test/all.rb
|
43
|
-
- lib/quality_extensions/test/
|
44
|
-
- lib/quality_extensions/
|
45
|
-
- lib/quality_extensions/
|
46
|
-
- lib/quality_extensions/
|
47
|
-
- lib/quality_extensions/kernel/
|
48
|
-
- lib/quality_extensions/kernel/require_all.rb
|
49
|
-
- lib/quality_extensions/kernel/simulate_input.rb
|
43
|
+
- lib/quality_extensions/test/difference_highlighting.rb
|
44
|
+
- lib/quality_extensions/test/assert_changed.rb
|
45
|
+
- lib/quality_extensions/dir/each_child.rb
|
46
|
+
- lib/quality_extensions/kernel/remove_const.rb
|
47
|
+
- lib/quality_extensions/kernel/windows_platform.rb
|
50
48
|
- lib/quality_extensions/kernel/die.rb
|
51
|
-
- lib/quality_extensions/kernel/require_once.rb
|
52
|
-
- lib/quality_extensions/kernel/require_local_all.rb
|
53
|
-
- lib/quality_extensions/kernel/example_printer.rb
|
54
|
-
- lib/quality_extensions/kernel/all.rb
|
55
49
|
- lib/quality_extensions/kernel/filter_output.rb
|
50
|
+
- lib/quality_extensions/kernel/remove_module.rb
|
51
|
+
- lib/quality_extensions/kernel/all.rb
|
56
52
|
- lib/quality_extensions/kernel/backtrace.rb
|
53
|
+
- lib/quality_extensions/kernel/simulate_input.rb
|
54
|
+
- lib/quality_extensions/kernel/require_local_all.rb
|
55
|
+
- lib/quality_extensions/kernel/require_all.rb
|
56
|
+
- lib/quality_extensions/kernel/require_once.rb
|
57
57
|
- lib/quality_extensions/kernel/capture_output.rb
|
58
|
-
- lib/quality_extensions/kernel/
|
59
|
-
- lib/quality_extensions/kernel/windows_platform.rb
|
60
|
-
- lib/quality_extensions/kernel/remove_const.rb
|
58
|
+
- lib/quality_extensions/kernel/example_printer.rb
|
61
59
|
- lib/quality_extensions/kernel/trap_chain.rb
|
62
|
-
- lib/quality_extensions/
|
63
|
-
- lib/quality_extensions/object/singleton_send.rb
|
64
|
-
- lib/quality_extensions/object/mcall.rb
|
65
|
-
- lib/quality_extensions/object/ancestry_of_method.rb
|
60
|
+
- lib/quality_extensions/object/send_if.rb
|
66
61
|
- lib/quality_extensions/object/send_if_not_nil.rb
|
67
|
-
- lib/quality_extensions/object/
|
68
|
-
- lib/quality_extensions/object/methods.rb
|
62
|
+
- lib/quality_extensions/object/ancestry_of_method.rb
|
69
63
|
- lib/quality_extensions/object/default.rb
|
70
|
-
- lib/quality_extensions/object/
|
64
|
+
- lib/quality_extensions/object/singleton_send.rb
|
65
|
+
- lib/quality_extensions/object/methods.rb
|
66
|
+
- lib/quality_extensions/object/ignore_access.rb
|
71
67
|
- lib/quality_extensions/object/if_else.rb
|
72
|
-
- lib/quality_extensions/
|
73
|
-
- lib/quality_extensions/
|
74
|
-
- lib/quality_extensions/
|
75
|
-
- lib/quality_extensions/date/all.rb
|
76
|
-
- lib/quality_extensions/date/month_ranges.rb
|
77
|
-
- lib/quality_extensions/time/deprecated.rb
|
68
|
+
- lib/quality_extensions/object/mcall.rb
|
69
|
+
- lib/quality_extensions/all.rb
|
70
|
+
- lib/quality_extensions/safe_nil.rb
|
78
71
|
- lib/quality_extensions/time/all.rb
|
79
|
-
- lib/quality_extensions/
|
72
|
+
- lib/quality_extensions/time/deprecated.rb
|
80
73
|
- lib/quality_extensions/find/select.rb
|
81
|
-
- lib/quality_extensions/
|
82
|
-
- lib/quality_extensions/
|
83
|
-
- lib/quality_extensions/
|
84
|
-
- lib/quality_extensions/
|
85
|
-
- lib/quality_extensions/
|
86
|
-
- lib/quality_extensions/
|
87
|
-
- lib/quality_extensions/
|
74
|
+
- lib/quality_extensions/regexp/join.rb
|
75
|
+
- lib/quality_extensions/enumerable/enum.rb
|
76
|
+
- lib/quality_extensions/enumerable/select_while.rb
|
77
|
+
- lib/quality_extensions/enumerable/select_until.rb
|
78
|
+
- lib/quality_extensions/hash/hash_select.rb
|
79
|
+
- lib/quality_extensions/hash/all.rb
|
80
|
+
- lib/quality_extensions/hash/to_date.rb
|
81
|
+
- lib/quality_extensions/hash/delete_unless.rb
|
82
|
+
- lib/quality_extensions/hash/to_query_string.rb
|
83
|
+
- lib/quality_extensions/module/malias_method_chain.rb
|
84
|
+
- lib/quality_extensions/module/remove_const.rb
|
85
|
+
- lib/quality_extensions/module/namespace.rb
|
86
|
+
- lib/quality_extensions/module/attribute_accessors.rb
|
87
|
+
- lib/quality_extensions/module/dirname.rb
|
88
88
|
- lib/quality_extensions/module/module_methods.rb
|
89
|
+
- lib/quality_extensions/module/alias_method_chain.rb
|
90
|
+
- lib/quality_extensions/module/bool_attr_accessor.rb
|
91
|
+
- lib/quality_extensions/module/class_methods.rb
|
92
|
+
- lib/quality_extensions/module/create_setter.rb
|
89
93
|
- lib/quality_extensions/module/alias_method.rb
|
90
|
-
- lib/quality_extensions/module/namespace.rb
|
91
|
-
- lib/quality_extensions/module/malias_method_chain.rb
|
92
94
|
- lib/quality_extensions/module/includable_once.rb
|
93
95
|
- lib/quality_extensions/module/parents.rb
|
94
|
-
- lib/quality_extensions/module/
|
95
|
-
- lib/quality_extensions/module/basename.rb
|
96
|
-
- lib/quality_extensions/module/create_setter.rb
|
97
|
-
- lib/quality_extensions/module/alias_method_chain.rb
|
98
|
-
- lib/quality_extensions/module/attribute_accessors.rb
|
96
|
+
- lib/quality_extensions/module/split.rb
|
99
97
|
- lib/quality_extensions/module/create.rb
|
100
|
-
- lib/quality_extensions/module/
|
101
|
-
- lib/quality_extensions/module/
|
98
|
+
- lib/quality_extensions/module/basename.rb
|
99
|
+
- lib/quality_extensions/module/guard_method.rb
|
100
|
+
- lib/quality_extensions/module/ancestry_of_instance_method.rb
|
102
101
|
- lib/quality_extensions/module/join.rb
|
103
|
-
- lib/quality_extensions/
|
104
|
-
- lib/quality_extensions/
|
105
|
-
- lib/quality_extensions/
|
106
|
-
- lib/quality_extensions/
|
107
|
-
- lib/quality_extensions/enumerable/select_until.rb
|
108
|
-
- lib/quality_extensions/enumerable/enum.rb
|
109
|
-
- lib/quality_extensions/hash/to_query_string.rb
|
110
|
-
- lib/quality_extensions/hash/all.rb
|
111
|
-
- lib/quality_extensions/hash/to_date.rb
|
112
|
-
- lib/quality_extensions/array/expand_ranges.rb
|
113
|
-
- lib/quality_extensions/array/shell_escape.rb
|
114
|
-
- lib/quality_extensions/array/classify.rb
|
115
|
-
- lib/quality_extensions/array/to_query_string.rb
|
102
|
+
- lib/quality_extensions/mutex/if_available.rb
|
103
|
+
- lib/quality_extensions/template.rb
|
104
|
+
- lib/quality_extensions/array/group_by.rb
|
105
|
+
- lib/quality_extensions/array/all.rb
|
116
106
|
- lib/quality_extensions/array/sequence.rb
|
117
107
|
- lib/quality_extensions/array/to_a_recursive.rb
|
118
|
-
- lib/quality_extensions/array/
|
108
|
+
- lib/quality_extensions/array/classify.rb
|
109
|
+
- lib/quality_extensions/array/expand_ranges.rb
|
110
|
+
- lib/quality_extensions/array/shell_escape.rb
|
119
111
|
- lib/quality_extensions/array/average.rb
|
120
|
-
- lib/quality_extensions/array/
|
121
|
-
- lib/quality_extensions/
|
122
|
-
- lib/quality_extensions/
|
123
|
-
- lib/quality_extensions/
|
112
|
+
- lib/quality_extensions/array/to_query_string.rb
|
113
|
+
- lib/quality_extensions/global_variable_set.rb
|
114
|
+
- lib/quality_extensions/exception/inspect_with_backtrace.rb
|
115
|
+
- lib/quality_extensions/month.rb
|
124
116
|
- lib/quality_extensions/string/md5.rb
|
125
117
|
- lib/quality_extensions/string/to_underscored_label.rb
|
126
|
-
- lib/quality_extensions/string/constantize.rb
|
127
118
|
- lib/quality_extensions/string/all.rb
|
119
|
+
- lib/quality_extensions/string/digits_only.rb
|
128
120
|
- lib/quality_extensions/string/each_char_with_index.rb
|
121
|
+
- lib/quality_extensions/string/with_knowledge_of_color.rb
|
122
|
+
- lib/quality_extensions/string/shell_escape.rb
|
123
|
+
- lib/quality_extensions/string/constantize.rb
|
124
|
+
- lib/quality_extensions/collection_extensions_for_cgi.rb
|
125
|
+
- lib/quality_extensions/file/exact_match_regexp.rb
|
126
|
+
- lib/quality_extensions/chainable_safe_nil.rb
|
127
|
+
- lib/quality_extensions/date/all.rb
|
128
|
+
- lib/quality_extensions/date/iso8601.rb
|
129
|
+
- lib/quality_extensions/date/month_ranges.rb
|
130
|
+
- lib/quality_extensions/date/deprecated.rb
|
131
|
+
- lib/quality_extensions/file_test/binary_file.rb
|
129
132
|
- test/all.rb
|
130
133
|
- Readme
|
131
134
|
test_files:
|
@@ -1,128 +0,0 @@
|
|
1
|
-
# CREDIT Michael Neumann
|
2
|
-
# CREDIT George Moschovitis
|
3
|
-
|
4
|
-
module Kernel
|
5
|
-
|
6
|
-
# Autoreload feature files.
|
7
|
-
#
|
8
|
-
# Automatically reload, at regular intervals, any previously loaded features,
|
9
|
-
# and/or other files not already loaded, if they have been modified since the last
|
10
|
-
# interval check. A numeric parameter sets the reload interval in seconds
|
11
|
-
# and the file parameter can either be a glob string or an array
|
12
|
-
# of file paths. If a glob string, it is expanded only once on the initial
|
13
|
-
# method call. Supplying a boolean parameter of 'false' will force autreload to
|
14
|
-
# skip previously loaded features and only reload the specified files.
|
15
|
-
# Also keeps a "dirty" flag.
|
16
|
-
|
17
|
-
def autoreload( *args )
|
18
|
-
|
19
|
-
check_interval=10
|
20
|
-
include_features = true
|
21
|
-
files = nil
|
22
|
-
|
23
|
-
args.each do |arg|
|
24
|
-
case arg
|
25
|
-
when Numeric
|
26
|
-
check_interval = arg
|
27
|
-
when String
|
28
|
-
files = Dir.glob( arg )
|
29
|
-
when Array
|
30
|
-
files = arg
|
31
|
-
when TrueClass, FalseClass
|
32
|
-
include_features = arg
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
file_mtime = {}
|
37
|
-
|
38
|
-
Thread.new(Time.now) do |start_time|
|
39
|
-
loop do
|
40
|
-
sleep check_interval
|
41
|
-
|
42
|
-
if include_features
|
43
|
-
feature_files = $LOADED_FEATURES.collect { |feature|
|
44
|
-
$LOAD_PATH.each { |lp| file = File.join(lp, feature) }
|
45
|
-
}.flatten
|
46
|
-
p feature_files
|
47
|
-
|
48
|
-
feature_files.each { |file|
|
49
|
-
if File.exists?(file) and (mtime = File.stat(file).mtime) > (file_mtime[file] || start_time)
|
50
|
-
$autoreload_dirty = true
|
51
|
-
file_mtime[file] = mtime
|
52
|
-
STDERR.puts "File '#{ file }' reloaded"
|
53
|
-
begin
|
54
|
-
load(file)
|
55
|
-
rescue Exception => e
|
56
|
-
STDERR.puts e.inspect
|
57
|
-
end
|
58
|
-
end
|
59
|
-
}
|
60
|
-
end
|
61
|
-
|
62
|
-
if files
|
63
|
-
files.each do |file|
|
64
|
-
if File.exists?(file) and (mtime = File.stat(file).mtime) > (file_mtime[file] || start_time)
|
65
|
-
$autoreload_dirty = true
|
66
|
-
file_mtime[file] = mtime
|
67
|
-
STDERR.puts "File '#{ file }' changed"
|
68
|
-
begin
|
69
|
-
load(file)
|
70
|
-
rescue Exception => e
|
71
|
-
STDERR.puts e.inspect
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
81
|
-
|
82
|
-
|
83
|
-
# Same as #autoreload, but does not include previously loaded features.
|
84
|
-
# This is equivalent to as adding a 'false' parameter to #autoreload.
|
85
|
-
|
86
|
-
def autoreload_files( *args )
|
87
|
-
autoreload( false, *args )
|
88
|
-
end
|
89
|
-
|
90
|
-
# deprecate
|
91
|
-
alias_method :autoreload_glob, :autoreload_files
|
92
|
-
|
93
|
-
end
|
94
|
-
|
95
|
-
#--
|
96
|
-
# # OLD VERSION
|
97
|
-
# def autoreload(check_interval=10)
|
98
|
-
# Thread.new(Time.now) { |start_time|
|
99
|
-
# file_mtime = {}
|
100
|
-
# loop {
|
101
|
-
# sleep check_interval
|
102
|
-
# $LOADED_FEATURES.each { |feature|
|
103
|
-
# $LOAD_PATH.each { |lp|
|
104
|
-
# file = File.join(lp, feature)
|
105
|
-
# if (File.exists?(file) and
|
106
|
-
# File.stat(file).mtime > (file_mtime[file] || start_time))
|
107
|
-
# file_mtime[file] = File.stat(file).mtime
|
108
|
-
# STDERR.puts "reload #{ file }"
|
109
|
-
# begin
|
110
|
-
# load(file)
|
111
|
-
# rescue Exception => e
|
112
|
-
# STDERR.puts e.inspect
|
113
|
-
# end
|
114
|
-
# end
|
115
|
-
# }
|
116
|
-
# }
|
117
|
-
# }
|
118
|
-
# }
|
119
|
-
# end
|
120
|
-
#++
|
121
|
-
|
122
|
-
# _____ _
|
123
|
-
# |_ _|__ ___| |_
|
124
|
-
# | |/ _ \/ __| __|
|
125
|
-
# | | __/\__ \ |_
|
126
|
-
# |_|\___||___/\__|
|
127
|
-
#
|
128
|
-
# TODO
|