extlib 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of extlib might be problematic. Click here for more details.
- data/LICENSE +20 -0
- data/README.txt +1 -1
- data/Rakefile +66 -11
- data/lib/extlib.rb +16 -3
- data/lib/extlib/blank.rb +19 -2
- data/lib/extlib/class.rb +175 -0
- data/lib/extlib/hash.rb +410 -0
- data/lib/extlib/hook.rb +4 -4
- data/lib/extlib/inflection.rb +3 -6
- data/lib/extlib/lazy_array.rb +1 -1
- data/lib/extlib/logger.rb +202 -0
- data/lib/extlib/mash.rb +143 -0
- data/lib/extlib/object.rb +141 -4
- data/lib/extlib/object_space.rb +13 -0
- data/lib/extlib/rubygems.rb +38 -0
- data/lib/extlib/simple_set.rb +39 -0
- data/lib/extlib/string.rb +87 -0
- data/lib/extlib/tasks/release.rb +15 -0
- data/lib/extlib/time.rb +12 -0
- data/lib/extlib/version.rb +1 -1
- data/lib/extlib/virtual_file.rb +10 -0
- metadata +23 -37
- data/.autotest +0 -21
- data/History.txt +0 -1
- data/Manifest.txt +0 -29
- data/spec/blank_spec.rb +0 -85
- data/spec/hook_spec.rb +0 -1198
- data/spec/inflection_spec.rb +0 -50
- data/spec/lazy_array_spec.rb +0 -896
- data/spec/module_spec.rb +0 -58
- data/spec/object_spec.rb +0 -4
- data/spec/pooling_spec.rb +0 -486
- data/spec/spec_helper.rb +0 -1
- data/spec/string_spec.rb +0 -4
- data/spec/struct_spec.rb +0 -12
- data/tasks/hoe.rb +0 -39
@@ -0,0 +1,38 @@
|
|
1
|
+
# this is a temporary workaround until rubygems Does the Right thing here
|
2
|
+
require 'rubygems'
|
3
|
+
module Gem
|
4
|
+
class SourceIndex
|
5
|
+
|
6
|
+
# This is resolved in 1.1
|
7
|
+
if Version.new(RubyGemsVersion) < Version.new("1.1")
|
8
|
+
|
9
|
+
# Overwrite this so that a gem of the same name and version won't push one
|
10
|
+
# from the gems directory out entirely.
|
11
|
+
#
|
12
|
+
# @param gem_spec<Gem::Specification> The specification of the gem to add.
|
13
|
+
def add_spec(gem_spec)
|
14
|
+
unless gem_spec.instance_variable_get("@loaded_from") &&
|
15
|
+
@gems[gem_spec.full_name].is_a?(Gem::Specification) &&
|
16
|
+
@gems[gem_spec.full_name].installation_path ==
|
17
|
+
File.join(defined?(Merb) && Merb.respond_to?(:root) ? Merb.root : Dir.pwd,"gems")
|
18
|
+
|
19
|
+
@gems[gem_spec.full_name] = gem_spec
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
class Specification
|
28
|
+
|
29
|
+
# Overwrite this so that gems in the gems directory get preferred over gems
|
30
|
+
# from any other location. If there are two gems of different versions in
|
31
|
+
# the gems directory, the later one will load as usual.
|
32
|
+
#
|
33
|
+
# @return <Array[Array]> The object used for sorting gem specs.
|
34
|
+
def sort_obj
|
35
|
+
[@name, installation_path == File.join(defined?(Merb) && Merb.respond_to?(:root) ? Merb.root : Dir.pwd,"gems") ? 1 : -1, @version.to_ints, @new_platform == Gem::Platform::RUBY ? -1 : 1]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Extlib
|
2
|
+
# Simple set implementation
|
3
|
+
# on top of Hash with merging support.
|
4
|
+
#
|
5
|
+
# In particular this is used to store
|
6
|
+
# a set of callable actions of controller.
|
7
|
+
class SimpleSet < Hash
|
8
|
+
|
9
|
+
# @param arr<Array> Initial set values.
|
10
|
+
#
|
11
|
+
# @return <Array> The array the Set was initialized with
|
12
|
+
def initialize(arr = [])
|
13
|
+
arr.each {|x| self[x] = true}
|
14
|
+
end
|
15
|
+
|
16
|
+
# @param value<Object> Value to add to set.
|
17
|
+
#
|
18
|
+
# @return <TrueClass>
|
19
|
+
def <<(value)
|
20
|
+
self[value] = true
|
21
|
+
end
|
22
|
+
|
23
|
+
# @param arr<Array> Values to merge with set.
|
24
|
+
#
|
25
|
+
# @return <SimpleSet> The set after the Array was merged in.
|
26
|
+
def merge(arr)
|
27
|
+
super(arr.inject({}) {|s,x| s[x] = true; s })
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return <String> A human readable version of the set.
|
31
|
+
def inspect
|
32
|
+
"#<SimpleSet: {#{keys.map {|x| x.inspect}.join(", ")}}>"
|
33
|
+
end
|
34
|
+
|
35
|
+
# def to_a
|
36
|
+
alias_method :to_a, :keys
|
37
|
+
|
38
|
+
end # SimpleSet
|
39
|
+
end # Merb
|
data/lib/extlib/string.rb
CHANGED
@@ -1,4 +1,91 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
1
3
|
class String
|
4
|
+
##
|
5
|
+
# @return <String> The string with all regexp special characters escaped.
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# "*?{}.".escape_regexp #=> "\\*\\?\\{\\}\\."
|
9
|
+
def escape_regexp
|
10
|
+
Regexp.escape self
|
11
|
+
end
|
12
|
+
|
13
|
+
##
|
14
|
+
# @return String The string with all regexp special characters unescaped.
|
15
|
+
#
|
16
|
+
# @example
|
17
|
+
# "\\*\\?\\{\\}\\.".unescape_regexp #=> "*?{}."
|
18
|
+
def unescape_regexp
|
19
|
+
self.gsub(/\\([\.\?\|\(\)\[\]\{\}\^\$\*\+\-])/, '\1')
|
20
|
+
end
|
21
|
+
|
22
|
+
##
|
23
|
+
# @return <String> The string converted to snake case.
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
# "FooBar".snake_case #=> "foo_bar"
|
27
|
+
# @example
|
28
|
+
# "HeadlineCNNNews".snake_case #=> "headline_cnn_news"
|
29
|
+
# @example
|
30
|
+
# "CNN".snake_case #=> "cnn"
|
31
|
+
def snake_case
|
32
|
+
return self.downcase if self =~ /^[A-Z]+$/
|
33
|
+
self.gsub(/([A-Z]+)(?=[A-Z][a-z]?)|\B[A-Z]/, '_\&') =~ /_*(.*)/
|
34
|
+
return $+.downcase
|
35
|
+
end
|
36
|
+
|
37
|
+
##
|
38
|
+
# @return <String> The string converted to camel case.
|
39
|
+
#
|
40
|
+
# @example
|
41
|
+
# "foo_bar".camel_case #=> "FooBar"
|
42
|
+
def camel_case
|
43
|
+
return self if self !~ /_/ && self =~ /[A-Z]+.*/
|
44
|
+
split('_').map{|e| e.capitalize}.join
|
45
|
+
end
|
46
|
+
|
47
|
+
##
|
48
|
+
# @return <String> The path string converted to a constant name.
|
49
|
+
#
|
50
|
+
# @example
|
51
|
+
# "merb/core_ext/string".to_const_string #=> "Merb::CoreExt::String"
|
52
|
+
def to_const_string
|
53
|
+
gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
54
|
+
end
|
55
|
+
|
56
|
+
##
|
57
|
+
# @return <String>
|
58
|
+
# The path that is associated with the constantized string, assuming a
|
59
|
+
# conventional structure.
|
60
|
+
#
|
61
|
+
# @example
|
62
|
+
# "FooBar::Baz".to_const_path # => "foo_bar/baz"
|
63
|
+
def to_const_path
|
64
|
+
snake_case.gsub(/::/, "/")
|
65
|
+
end
|
66
|
+
|
67
|
+
##
|
68
|
+
# @param o<String> The path component to join with the string.
|
69
|
+
#
|
70
|
+
# @return <String> The original path concatenated with o.
|
71
|
+
#
|
72
|
+
# @example
|
73
|
+
# "merb"/"core_ext" #=> "merb/core_ext"
|
74
|
+
def /(o)
|
75
|
+
File.join(self, o.to_s)
|
76
|
+
end
|
77
|
+
|
78
|
+
##
|
79
|
+
# @param other<String> Base path to calculate against
|
80
|
+
#
|
81
|
+
# @return <String> Relative path from between the two
|
82
|
+
#
|
83
|
+
# @example
|
84
|
+
# "/opt/local/lib".relative_path_from("/opt/local/lib/ruby/site_ruby") # => "../.."
|
85
|
+
def relative_path_from(other)
|
86
|
+
Pathname.new(self).relative_path_from(Pathname.new(other)).to_s
|
87
|
+
end
|
88
|
+
|
2
89
|
# Overwrite this method to provide your own translations.
|
3
90
|
def self.translate(value)
|
4
91
|
translations[value] || value
|
@@ -0,0 +1,15 @@
|
|
1
|
+
desc "Publish the release files to RubyForge."
|
2
|
+
task :release => [ :package ] do
|
3
|
+
packages = %w( gem tgz zip ).collect{ |ext| "pkg/#{GEM_NAME}-#{GEM_VERSION}.#{ext}" }
|
4
|
+
|
5
|
+
begin
|
6
|
+
sh %{rubyforge login}
|
7
|
+
sh %{rubyforge add_release #{RUBY_FORGE_PROJECT} #{GEM_NAME} #{GEM_VERSION} #{packages.join(' ')}}
|
8
|
+
sh %{rubyforge add_file #{RUBY_FORGE_PROJECT} #{GEM_NAME} #{GEM_VERSION} #{packages.join(' ')}}
|
9
|
+
rescue Exception => e
|
10
|
+
puts
|
11
|
+
puts "Release failed: #{e.message}"
|
12
|
+
puts
|
13
|
+
puts "Set PKG_BUILD environment variable if you do a subrelease (0.9.4.2008_08_02 when version is 0.9.4)"
|
14
|
+
end
|
15
|
+
end
|
data/lib/extlib/time.rb
ADDED
data/lib/extlib/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: extlib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Smoot
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-08-12 00:00:00 +03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -22,63 +22,49 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: 0.2.0
|
24
24
|
version:
|
25
|
-
|
26
|
-
|
27
|
-
type: :development
|
28
|
-
version_requirement:
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 1.7.0
|
34
|
-
version:
|
35
|
-
description: Support Library for DataMapper and DataObjects
|
36
|
-
email:
|
37
|
-
- ssmoot@gmail.com
|
25
|
+
description: Support library for DataMapper and Merb.
|
26
|
+
email: ssmoot@gmail.com
|
38
27
|
executables: []
|
39
28
|
|
40
29
|
extensions: []
|
41
30
|
|
42
31
|
extra_rdoc_files:
|
43
|
-
-
|
44
|
-
- Manifest.txt
|
32
|
+
- LICENSE
|
45
33
|
- README.txt
|
46
34
|
files:
|
47
|
-
-
|
48
|
-
- History.txt
|
49
|
-
- Manifest.txt
|
35
|
+
- LICENSE
|
50
36
|
- README.txt
|
51
37
|
- Rakefile
|
52
|
-
- lib/extlib
|
38
|
+
- lib/extlib
|
53
39
|
- lib/extlib/assertions.rb
|
54
40
|
- lib/extlib/blank.rb
|
41
|
+
- lib/extlib/class.rb
|
42
|
+
- lib/extlib/hash.rb
|
55
43
|
- lib/extlib/hook.rb
|
56
44
|
- lib/extlib/inflection.rb
|
57
45
|
- lib/extlib/lazy_array.rb
|
46
|
+
- lib/extlib/logger.rb
|
47
|
+
- lib/extlib/mash.rb
|
58
48
|
- lib/extlib/module.rb
|
59
49
|
- lib/extlib/object.rb
|
50
|
+
- lib/extlib/object_space.rb
|
60
51
|
- lib/extlib/pathname.rb
|
61
52
|
- lib/extlib/pooling.rb
|
53
|
+
- lib/extlib/rubygems.rb
|
54
|
+
- lib/extlib/simple_set.rb
|
62
55
|
- lib/extlib/string.rb
|
63
56
|
- lib/extlib/struct.rb
|
57
|
+
- lib/extlib/tasks
|
58
|
+
- lib/extlib/tasks/release.rb
|
59
|
+
- lib/extlib/time.rb
|
64
60
|
- lib/extlib/version.rb
|
65
|
-
-
|
66
|
-
-
|
67
|
-
- spec/inflection_spec.rb
|
68
|
-
- spec/lazy_array_spec.rb
|
69
|
-
- spec/module_spec.rb
|
70
|
-
- spec/object_spec.rb
|
71
|
-
- spec/pooling_spec.rb
|
72
|
-
- spec/spec_helper.rb
|
73
|
-
- spec/string_spec.rb
|
74
|
-
- spec/struct_spec.rb
|
75
|
-
- tasks/hoe.rb
|
61
|
+
- lib/extlib/virtual_file.rb
|
62
|
+
- lib/extlib.rb
|
76
63
|
has_rdoc: false
|
77
64
|
homepage: http://extlib.rubyforge.org
|
78
65
|
post_install_message:
|
79
|
-
rdoc_options:
|
80
|
-
|
81
|
-
- README.txt
|
66
|
+
rdoc_options: []
|
67
|
+
|
82
68
|
require_paths:
|
83
69
|
- lib
|
84
70
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -95,10 +81,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
81
|
version:
|
96
82
|
requirements: []
|
97
83
|
|
98
|
-
rubyforge_project:
|
84
|
+
rubyforge_project:
|
99
85
|
rubygems_version: 1.2.0
|
100
86
|
signing_key:
|
101
87
|
specification_version: 2
|
102
|
-
summary: Support
|
88
|
+
summary: Support library for DataMapper and Merb.
|
103
89
|
test_files: []
|
104
90
|
|
data/.autotest
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
Autotest.add_hook :initialize do |at|
|
2
|
-
ignore = %w[ .git log plugins script tasks bin CHANGELOG FAQ MIT-LICENSE QUICKLINKS README ]
|
3
|
-
|
4
|
-
ignore.each do |exception|
|
5
|
-
at.add_exception(exception)
|
6
|
-
end
|
7
|
-
|
8
|
-
at.clear_mappings
|
9
|
-
|
10
|
-
at.add_mapping(%r{^spec/.+_spec\.rb$}) do |filename,_|
|
11
|
-
filename
|
12
|
-
end
|
13
|
-
|
14
|
-
at.add_mapping(%r{^lib/extlib/(.+)\.rb$}) do |_,match|
|
15
|
-
[ "spec/#{match[1]}_spec.rb" ]
|
16
|
-
end
|
17
|
-
|
18
|
-
at.add_mapping(%r{^spec/spec_helper\.rb$}) do
|
19
|
-
at.files_matching(%r{^spec/.+_spec\.rb$})
|
20
|
-
end
|
21
|
-
end
|
data/History.txt
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
|
data/Manifest.txt
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
.autotest
|
2
|
-
History.txt
|
3
|
-
Manifest.txt
|
4
|
-
README.txt
|
5
|
-
Rakefile
|
6
|
-
lib/extlib.rb
|
7
|
-
lib/extlib/assertions.rb
|
8
|
-
lib/extlib/blank.rb
|
9
|
-
lib/extlib/hook.rb
|
10
|
-
lib/extlib/inflection.rb
|
11
|
-
lib/extlib/lazy_array.rb
|
12
|
-
lib/extlib/module.rb
|
13
|
-
lib/extlib/object.rb
|
14
|
-
lib/extlib/pathname.rb
|
15
|
-
lib/extlib/pooling.rb
|
16
|
-
lib/extlib/string.rb
|
17
|
-
lib/extlib/struct.rb
|
18
|
-
lib/extlib/version.rb
|
19
|
-
spec/blank_spec.rb
|
20
|
-
spec/hook_spec.rb
|
21
|
-
spec/inflection_spec.rb
|
22
|
-
spec/lazy_array_spec.rb
|
23
|
-
spec/module_spec.rb
|
24
|
-
spec/object_spec.rb
|
25
|
-
spec/pooling_spec.rb
|
26
|
-
spec/spec_helper.rb
|
27
|
-
spec/string_spec.rb
|
28
|
-
spec/struct_spec.rb
|
29
|
-
tasks/hoe.rb
|
data/spec/blank_spec.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
|
-
|
3
|
-
describe Object do
|
4
|
-
it 'should provide blank?' do
|
5
|
-
Object.new.should respond_to(:blank?)
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'should be blank if it is nil' do
|
9
|
-
object = Object.new
|
10
|
-
class << object
|
11
|
-
def nil?; true end
|
12
|
-
end
|
13
|
-
object.should be_blank
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should be blank if it is empty' do
|
17
|
-
{}.should be_blank
|
18
|
-
[].should be_blank
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should not be blank if not nil or empty' do
|
22
|
-
Object.new.should_not be_blank
|
23
|
-
[nil].should_not be_blank
|
24
|
-
{ nil => 0 }.should_not be_blank
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe Numeric do
|
29
|
-
it 'should provide blank?' do
|
30
|
-
1.should respond_to(:blank?)
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should never be blank' do
|
34
|
-
1.should_not be_blank
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe NilClass do
|
39
|
-
it 'should provide blank?' do
|
40
|
-
nil.should respond_to(:blank?)
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'should always be blank' do
|
44
|
-
nil.should be_blank
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe TrueClass do
|
49
|
-
it 'should provide blank?' do
|
50
|
-
true.should respond_to(:blank?)
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'should never be blank' do
|
54
|
-
true.should_not be_blank
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe FalseClass do
|
59
|
-
it 'should provide blank?' do
|
60
|
-
false.should respond_to(:blank?)
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'should always be blank' do
|
64
|
-
false.should be_blank
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe String do
|
69
|
-
it 'should provide blank?' do
|
70
|
-
'string'.should respond_to(:blank?)
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'should be blank if empty' do
|
74
|
-
''.should be_blank
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'should be blank if it only contains whitespace' do
|
78
|
-
' '.should be_blank
|
79
|
-
" \r \n \t ".should be_blank
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'should not be blank if it contains non-whitespace' do
|
83
|
-
' a '.should_not be_blank
|
84
|
-
end
|
85
|
-
end
|