ruby_ext 0.5.8 → 0.5.9
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/lib/rake_ext.rb +2 -2
- data/lib/ruby_ext/core/hash.rb +11 -0
- data/lib/ruby_ext/core/module.rb +2 -3
- data/lib/ruby_ext/core/object.rb +10 -3
- data/lib/ruby_ext/core/string.rb +10 -27
- data/lib/ruby_ext/core.rb +2 -2
- data/lib/ruby_ext/fixes.rb +1 -1
- data/lib/ruby_ext/more/callbacks.rb +3 -5
- data/lib/ruby_ext/more/declarative_cache.rb +1 -17
- data/lib/ruby_ext/more/open_constructor.rb +0 -1
- data/lib/ruby_ext/more.rb +31 -10
- data/spec/more/declarative_cache_spec.rb +2 -2
- metadata +2 -5
- data/lib/ruby_ext/gems.rb +0 -0
- data/lib/ruby_ext/more/miscellaneous.rb +0 -7
- data/lib/yaml_fix.rb +0 -9
data/lib/rake_ext.rb
CHANGED
data/lib/ruby_ext/core/hash.rb
CHANGED
@@ -19,11 +19,22 @@ class Hash
|
|
19
19
|
raise "unknown options :#{unknown_options.join(': ')}!" unless unknown_options.empty?
|
20
20
|
end
|
21
21
|
|
22
|
+
def reverse_merge(other_hash)
|
23
|
+
other_hash.merge(self)
|
24
|
+
end
|
25
|
+
|
26
|
+
def reverse_merge!(other_hash)
|
27
|
+
merge!( other_hash ){|key,left,right| left }
|
28
|
+
end
|
29
|
+
|
30
|
+
# Haml relies on :inspect default format, can't use it.
|
31
|
+
#
|
22
32
|
# def inspect
|
23
33
|
# "{" + collect{|k, v| "#{k}: #{v}"}.join(', ') + "}"
|
24
34
|
# end
|
25
35
|
# alias_method :to_s, :inspect
|
26
36
|
|
27
37
|
alias_method :blank?, :empty?
|
38
|
+
|
28
39
|
alias_method :to_h, :to_hash
|
29
40
|
end
|
data/lib/ruby_ext/core/module.rb
CHANGED
@@ -90,7 +90,7 @@ Module.class_eval do
|
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
-
raise "Internal error, it shouldn't be loaded twice!" if defined? ESCAPE_METHOD_SYMBOLS # some tricky error when runing spec with rake
|
93
|
+
raise "Internal error, it shouldn't be loaded twice!" if defined? ESCAPE_METHOD_SYMBOLS # some tricky error when runing spec with rake.
|
94
94
|
ESCAPE_METHOD_SYMBOLS = [
|
95
95
|
['==', 'assign'],
|
96
96
|
['>', 'gt'],
|
@@ -124,8 +124,7 @@ Module.class_eval do
|
|
124
124
|
|
125
125
|
public :include, :define_method
|
126
126
|
|
127
|
-
|
128
|
-
# copied from rails
|
127
|
+
# Copied from rails.
|
129
128
|
def delegate(*methods)
|
130
129
|
options = methods.pop
|
131
130
|
unless options.is_a?(Hash) && to = options[:to]
|
data/lib/ruby_ext/core/object.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
Object.class_eval do
|
2
2
|
def self; self end
|
3
3
|
|
4
|
+
def present?
|
5
|
+
!blank?
|
6
|
+
end
|
7
|
+
|
8
|
+
def blank?
|
9
|
+
respond_to?(:empty?) ? empty? : !self
|
10
|
+
end
|
11
|
+
|
4
12
|
def metaclass &block
|
5
13
|
(class << self; self; end)
|
6
14
|
end
|
@@ -17,8 +25,7 @@ Object.class_eval do
|
|
17
25
|
self && self.send(method, *args, &block)
|
18
26
|
end
|
19
27
|
|
28
|
+
alias_method :instance_variable_names, :instance_variables
|
29
|
+
|
20
30
|
public :extend
|
21
|
-
# def copy
|
22
|
-
# Marshal.load(Marshal.dump self) # Stub
|
23
|
-
# end
|
24
31
|
end
|
data/lib/ruby_ext/core/string.rb
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
String.class_eval do
|
2
|
+
def indent spaces = 2
|
3
|
+
indent = ' ' * spaces
|
4
|
+
gsub /^/, indent
|
5
|
+
end
|
6
|
+
|
2
7
|
def rsplit *args
|
3
8
|
reverse.split(*args).collect(&:reverse).reverse
|
4
9
|
end
|
@@ -11,30 +16,10 @@ String.class_eval do
|
|
11
16
|
File.expand_path(self)
|
12
17
|
end
|
13
18
|
|
14
|
-
# def to_reader
|
15
|
-
# self.to_sym
|
16
|
-
# end
|
17
|
-
|
18
|
-
# def to_writer
|
19
|
-
# "#{self}=".to_sym
|
20
|
-
# end
|
21
|
-
|
22
|
-
# def to_iv
|
23
|
-
# "@#{self}"
|
24
|
-
# end
|
25
|
-
|
26
19
|
def to_a
|
27
20
|
[self]
|
28
21
|
end
|
29
22
|
|
30
|
-
# def interpolate binding
|
31
|
-
# binding.must_be.a Binding
|
32
|
-
# return gsub(/\#\{.+?\}/) do |term|
|
33
|
-
# identifier = term.slice(2 .. term.size-2)
|
34
|
-
# binding.eval identifier
|
35
|
-
# end
|
36
|
-
# end
|
37
|
-
|
38
23
|
def self.secure_token
|
39
24
|
original = [Time.now, (1..10).map{ rand.to_s }]
|
40
25
|
Digest::SHA1.hexdigest(original.flatten.join('--'))
|
@@ -69,14 +54,12 @@ String.class_eval do
|
|
69
54
|
constant
|
70
55
|
end
|
71
56
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
57
|
+
def substitute(*args)
|
58
|
+
gsub(*args){yield Regexp.last_match.captures}
|
59
|
+
end
|
76
60
|
|
77
|
-
|
78
|
-
|
79
|
-
end
|
61
|
+
def substitute!(*args)
|
62
|
+
gsub!(*args){yield Regexp.last_match.captures}
|
80
63
|
end
|
81
64
|
|
82
65
|
alias_method :blank?, :empty?
|
data/lib/ruby_ext/core.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
raise 'ruby 1.9.2 or higher required!' if RUBY_VERSION < '1.9.2'
|
2
2
|
|
3
|
-
require 'ruby_ext/gems'
|
4
3
|
require 'ruby_ext/fixes'
|
5
4
|
|
5
|
+
autoload :OpenObject, 'ruby_ext/core/open_object'
|
6
|
+
|
6
7
|
%w(
|
7
8
|
basic_object
|
8
9
|
nil_class
|
@@ -15,7 +16,6 @@ require 'ruby_ext/fixes'
|
|
15
16
|
string
|
16
17
|
symbol
|
17
18
|
must
|
18
|
-
open_object
|
19
19
|
deep_clone
|
20
20
|
time
|
21
21
|
multiple_inheritance
|
data/lib/ruby_ext/fixes.rb
CHANGED
@@ -181,9 +181,9 @@ module RubyExt::Callbacks
|
|
181
181
|
|
182
182
|
def set_callback callback_name, type, *executor_or_options, &block
|
183
183
|
callback_name.must_be.a Symbol
|
184
|
-
type = type.to_sym
|
184
|
+
type = type.to_sym
|
185
185
|
|
186
|
-
#
|
186
|
+
# Parsing arguments.
|
187
187
|
opt = executor_or_options.extract_options!
|
188
188
|
"You can't provide both method name and block for filter!" if block and !executor_or_options.empty?
|
189
189
|
executor = block || executor_or_options.first
|
@@ -191,7 +191,7 @@ module RubyExt::Callbacks
|
|
191
191
|
type.must_be.in [:before, :around, :after]
|
192
192
|
executor.must_be.defined
|
193
193
|
|
194
|
-
#
|
194
|
+
# Creating callback.
|
195
195
|
callback = AbstractCallback.new
|
196
196
|
callback = case type
|
197
197
|
when :before then BeforeCallback.new
|
@@ -204,8 +204,6 @@ module RubyExt::Callbacks
|
|
204
204
|
callback.conditions = opt
|
205
205
|
|
206
206
|
(self.callbacks[callback_name] ||= []) << callback
|
207
|
-
# callbacks.send(type) << callback
|
208
|
-
# (callbacks[callback_name][type] ||= []) << callback
|
209
207
|
end
|
210
208
|
|
211
209
|
end
|
@@ -1,22 +1,6 @@
|
|
1
1
|
require 'monitor'
|
2
2
|
|
3
|
-
|
4
|
-
def cache_method *methods
|
5
|
-
DeclarativeCache.cache_method self, *methods
|
6
|
-
end
|
7
|
-
|
8
|
-
def cache_method_with_params *methods
|
9
|
-
DeclarativeCache.cache_method_with_params self, *methods
|
10
|
-
end
|
11
|
-
|
12
|
-
def clear_cache obj
|
13
|
-
obj.instance_variables.each do |iv|
|
14
|
-
obj.send :remove_instance_variable, iv if iv =~ /_cache$/ or iv =~ /_cache_check$/
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
module DeclarativeCache
|
3
|
+
module RubyExt::DeclarativeCache
|
20
4
|
DISABLED = false
|
21
5
|
|
22
6
|
warn "CASHE DISABLED" if DISABLED
|
data/lib/ruby_ext/more.rb
CHANGED
@@ -1,12 +1,33 @@
|
|
1
1
|
require 'ruby_ext/core'
|
2
2
|
|
3
|
-
module RubyExt
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
3
|
+
module RubyExt
|
4
|
+
%w(Callbacks DeclarativeCache Observable OpenConstructor Tuple).each do |const|
|
5
|
+
autoload const, "ruby_ext/more/#{const.underscore}"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
# Declarative cache.
|
10
|
+
Module.class_eval do
|
11
|
+
def cache_method *methods
|
12
|
+
::RubyExt::DeclarativeCache.cache_method self, *methods
|
13
|
+
end
|
14
|
+
|
15
|
+
def cache_method_with_params *methods
|
16
|
+
::RubyExt::DeclarativeCache.cache_method_with_params self, *methods
|
17
|
+
end
|
18
|
+
|
19
|
+
def clear_cache obj
|
20
|
+
obj.instance_variables.each do |iv|
|
21
|
+
obj.send :remove_instance_variable, iv if iv =~ /_cache$/ or iv =~ /_cache_check$/
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Printing with multiple arguments.
|
27
|
+
Kernel.class_eval do
|
28
|
+
alias_method :old_p, :p
|
29
|
+
def p *args
|
30
|
+
puts args.collect{|a| a.inspect}.join(' ')
|
31
|
+
return *args
|
32
|
+
end
|
33
|
+
end
|
@@ -19,8 +19,8 @@ describe 'DeclarativeCache' do
|
|
19
19
|
cache_method_with_params '*'
|
20
20
|
end
|
21
21
|
|
22
|
-
DeclarativeCache.cache_method CachedClass, :value2_get
|
23
|
-
DeclarativeCache.cache_method_with_params CachedClass, :params_get
|
22
|
+
RubyExt::DeclarativeCache.cache_method CachedClass, :value2_get
|
23
|
+
RubyExt::DeclarativeCache.cache_method_with_params CachedClass, :params_get
|
24
24
|
|
25
25
|
it "Simple Cache" do
|
26
26
|
o = CachedClass.new
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-10-24 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email:
|
@@ -42,16 +42,13 @@ files:
|
|
42
42
|
- lib/ruby_ext/core/true_class.rb
|
43
43
|
- lib/ruby_ext/core.rb
|
44
44
|
- lib/ruby_ext/fixes.rb
|
45
|
-
- lib/ruby_ext/gems.rb
|
46
45
|
- lib/ruby_ext/more/callbacks.rb
|
47
46
|
- lib/ruby_ext/more/declarative_cache.rb
|
48
|
-
- lib/ruby_ext/more/miscellaneous.rb
|
49
47
|
- lib/ruby_ext/more/observable.rb
|
50
48
|
- lib/ruby_ext/more/open_constructor.rb
|
51
49
|
- lib/ruby_ext/more/tuple.rb
|
52
50
|
- lib/ruby_ext/more.rb
|
53
51
|
- lib/ruby_ext.rb
|
54
|
-
- lib/yaml_fix.rb
|
55
52
|
- spec/core/array_spec.rb
|
56
53
|
- spec/core/deep_clone_spec.rb
|
57
54
|
- spec/core/enumerable.rb
|
data/lib/ruby_ext/gems.rb
DELETED
File without changes
|
data/lib/yaml_fix.rb
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
begin
|
4
|
-
require 'psych'
|
5
|
-
YAML::ENGINE.yamler = 'psych'
|
6
|
-
rescue Exception
|
7
|
-
warn "can't load 'psych', the new YAML engine (probably the 'libyaml' is not installed), usng 'sych' a deprecated one, \
|
8
|
-
there may be some problems with encoding."
|
9
|
-
end
|