vex 0.4.4 → 0.6.2
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/.gitignore +10 -0
- data/Manifest +105 -0
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/gem.yml +13 -0
- data/lib/vex/action_controller/error.rb +8 -0
- data/lib/vex/action_controller/partial_helper.rb +9 -17
- data/lib/vex/action_controller/whitelisted_actions.rb +5 -1
- data/lib/vex/active_record/__init__.rb +4 -0
- data/lib/vex/active_record/cached_column.rb +61 -0
- data/lib/vex/active_record/cached_column/etest.rb +86 -0
- data/lib/vex/active_record/errors.rb +7 -0
- data/lib/vex/active_record/lite_table.rb +17 -13
- data/lib/vex/active_record/plugins/default_value_for/.gitignore +1 -0
- data/lib/vex/active_record/with_scope.rb +23 -0
- data/lib/vex/base/cgi_ext.rb +44 -0
- data/lib/vex/base/hash/slop.rb +4 -2
- data/lib/vex/base/local_conf.rb +2 -7
- data/lib/vex/base/string/string_ext.rb +5 -0
- data/lib/vex/boot/hash.rb +17 -0
- data/vex/gem.rake +36 -0
- data/vex/gem.rb +95 -0
- metadata +34 -119
- data/config/README +0 -2
- data/config/dependencies.rb +0 -10
- data/config/gem.yml +0 -11
- data/lib/vex/base/filesystem/lock.rb.test.lck +0 -0
- data/lib/vex/base/filesystem/lock.rb.test.pid +0 -1
- data/lib/vex/base/object/with_benchmark.rb +0 -110
- data/tasks/echoe.rake +0 -52
- data/vex.gemspec +0 -46
data/.gitignore
ADDED
data/Manifest
CHANGED
@@ -0,0 +1,105 @@
|
|
1
|
+
CHANGELOG
|
2
|
+
Manifest
|
3
|
+
NOTICE.txt
|
4
|
+
Rakefile
|
5
|
+
VERSION
|
6
|
+
config/README
|
7
|
+
config/dependencies.rb
|
8
|
+
config/gem.yml
|
9
|
+
init.rb
|
10
|
+
lib/nokogiri/nokogiri_ext.rb
|
11
|
+
lib/vex.rb
|
12
|
+
lib/vex/action_controller.rb
|
13
|
+
lib/vex/action_controller/error.rb
|
14
|
+
lib/vex/action_controller/output_logging.rb
|
15
|
+
lib/vex/action_controller/partial_helper.rb
|
16
|
+
lib/vex/action_controller/verify_action.rb
|
17
|
+
lib/vex/action_controller/verify_hostname.rb
|
18
|
+
lib/vex/action_controller/whitelisted_actions.rb
|
19
|
+
lib/vex/active_record.rb
|
20
|
+
lib/vex/active_record/__init__.rb
|
21
|
+
lib/vex/active_record/advisory_lock.rb
|
22
|
+
lib/vex/active_record/advisory_lock/mysql_adapter.rb
|
23
|
+
lib/vex/active_record/advisory_lock/sqlite_adapter.rb
|
24
|
+
lib/vex/active_record/belongs_to_many.rb
|
25
|
+
lib/vex/active_record/custom_validations.rb
|
26
|
+
lib/vex/active_record/find_by_extension.rb
|
27
|
+
lib/vex/active_record/gem.rb
|
28
|
+
lib/vex/active_record/lite_table.rb
|
29
|
+
lib/vex/active_record/lite_view.rb
|
30
|
+
lib/vex/active_record/mass_load.rb
|
31
|
+
lib/vex/active_record/mysql_backup.rb
|
32
|
+
lib/vex/active_record/plugins/default_value_for/LICENSE.TXT
|
33
|
+
lib/vex/active_record/plugins/default_value_for/README.rdoc
|
34
|
+
lib/vex/active_record/plugins/default_value_for/Rakefile
|
35
|
+
lib/vex/active_record/plugins/default_value_for/init.rb
|
36
|
+
lib/vex/active_record/plugins/default_value_for/test.rb
|
37
|
+
lib/vex/active_record/random_id.rb
|
38
|
+
lib/vex/active_record/resolver.rb
|
39
|
+
lib/vex/active_record/serialize_hash.rb
|
40
|
+
lib/vex/active_record/to_html.rb
|
41
|
+
lib/vex/active_record/validate.rb
|
42
|
+
lib/vex/active_record/validation_error_ext.rb
|
43
|
+
lib/vex/base.rb
|
44
|
+
lib/vex/base/app.rb
|
45
|
+
lib/vex/base/argv.rb
|
46
|
+
lib/vex/base/array/at_random.rb
|
47
|
+
lib/vex/base/array/avg.rb
|
48
|
+
lib/vex/base/array/cross.rb
|
49
|
+
lib/vex/base/array/each_batch.rb
|
50
|
+
lib/vex/base/array/parallel_map.rb
|
51
|
+
lib/vex/base/deprecation.rb
|
52
|
+
lib/vex/base/enumerable/deep.rb
|
53
|
+
lib/vex/base/enumerable/enumerable_ext.rb
|
54
|
+
lib/vex/base/enumerable/progress.rb
|
55
|
+
lib/vex/base/filesystem/fast_copy.rb
|
56
|
+
lib/vex/base/filesystem/grep.rb
|
57
|
+
lib/vex/base/filesystem/lock.rb
|
58
|
+
lib/vex/base/filesystem/lock.rb.test.lck
|
59
|
+
lib/vex/base/filesystem/lock.rb.test.pid
|
60
|
+
lib/vex/base/filesystem/make_dirs.rb
|
61
|
+
lib/vex/base/filesystem/parse_filename.rb
|
62
|
+
lib/vex/base/filesystem/tmp_file.rb
|
63
|
+
lib/vex/base/filesystem/write.rb
|
64
|
+
lib/vex/base/hash/compact.rb
|
65
|
+
lib/vex/base/hash/cross.rb
|
66
|
+
lib/vex/base/hash/ensure_keys.rb
|
67
|
+
lib/vex/base/hash/extract.rb
|
68
|
+
lib/vex/base/hash/extras.rb
|
69
|
+
lib/vex/base/hash/inspect.rb
|
70
|
+
lib/vex/base/hash/slop.rb
|
71
|
+
lib/vex/base/invalid_argument/invalid_argument.rb
|
72
|
+
lib/vex/base/local_conf.rb
|
73
|
+
lib/vex/base/net/http_ext.rb
|
74
|
+
lib/vex/base/net/socket_ext.rb
|
75
|
+
lib/vex/base/object/in.rb
|
76
|
+
lib/vex/base/object/insp.rb
|
77
|
+
lib/vex/base/object/multiple_attributes.rb
|
78
|
+
lib/vex/base/object/singleton_methods.rb
|
79
|
+
lib/vex/base/object/with_benchmark.rb
|
80
|
+
lib/vex/base/range_array.rb
|
81
|
+
lib/vex/base/range_ext.rb
|
82
|
+
lib/vex/base/safe_token.rb
|
83
|
+
lib/vex/base/string/iconvert.rb
|
84
|
+
lib/vex/base/string/string_ext.rb
|
85
|
+
lib/vex/base/system.rb
|
86
|
+
lib/vex/base/thread/deferred.rb
|
87
|
+
lib/vex/base/thread/sleep.rb
|
88
|
+
lib/vex/base/time/date_ext.rb
|
89
|
+
lib/vex/boot.rb
|
90
|
+
lib/vex/boot/array.rb
|
91
|
+
lib/vex/boot/blank.rb
|
92
|
+
lib/vex/boot/string.rb
|
93
|
+
migration/create_request_log.rb
|
94
|
+
script/console
|
95
|
+
script/rebuild
|
96
|
+
tasks/echoe.rake
|
97
|
+
tasks/validate_db.rake
|
98
|
+
test/ar.rb
|
99
|
+
test/auto.rb
|
100
|
+
test/base-tests/local_conf.rb
|
101
|
+
test/base.rb
|
102
|
+
test/boot.rb
|
103
|
+
test/config/local.defaults.yml
|
104
|
+
test/config/local.yml
|
105
|
+
test/test_helper.rb
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.7
|
data/gem.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
name: "vex"
|
2
|
+
version: "0.6.2"
|
3
|
+
summary: "Vex: some ruby extensions"
|
4
|
+
description: "Vex: some ruby extensions"
|
5
|
+
homepage: http://github.com/pboy/vex
|
6
|
+
author: pboy
|
7
|
+
email: eno-pboy@open-lab.org
|
8
|
+
dependencies:
|
9
|
+
- etest
|
10
|
+
- nokogiri
|
11
|
+
- sanitize
|
12
|
+
- htmlentities
|
13
|
+
- json
|
@@ -20,6 +20,14 @@ module ActionController::Error
|
|
20
20
|
base.rescue_from ActionController::UnknownAction, :with => :rescue_404
|
21
21
|
end
|
22
22
|
|
23
|
+
def to_s
|
24
|
+
"#{super}: #{@text}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def inspect
|
28
|
+
"#{super}: #{@text.inspect}"
|
29
|
+
end
|
30
|
+
|
23
31
|
private
|
24
32
|
|
25
33
|
def rescue_404
|
@@ -1,4 +1,12 @@
|
|
1
1
|
module ActionController::PartialHelper
|
2
|
+
def self.disable_localite
|
3
|
+
@no_localite = true
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.localite?
|
7
|
+
defined?(Localite) && !@no_localite
|
8
|
+
end
|
9
|
+
|
2
10
|
def partial_for(name)
|
3
11
|
case name
|
4
12
|
when String then name
|
@@ -32,25 +40,9 @@ module ActionController::PartialHelper
|
|
32
40
|
opts[:collection] = locals[:collection]
|
33
41
|
end
|
34
42
|
|
35
|
-
|
36
|
-
# set up localite??
|
37
|
-
if defined?(Localite) && !(scope = File.basename(partial).gsub(/\..*/, "")).blank?
|
38
|
-
Localite.scope(scope) do
|
39
|
-
render_vex_partial(opts)
|
40
|
-
end
|
41
|
-
else
|
42
|
-
render_vex_partial(opts)
|
43
|
-
end
|
43
|
+
render_vex_partial(opts)
|
44
44
|
end
|
45
45
|
|
46
|
-
def render_vex_partial(opts)
|
47
|
-
if self.is_a?(ActionController::Base)
|
48
|
-
render_to_string(opts)
|
49
|
-
else
|
50
|
-
render(opts)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
46
|
def partial?(*args)
|
55
47
|
partial *args
|
56
48
|
rescue ActionView::MissingTemplate
|
@@ -20,11 +20,15 @@ class ActionController::Base
|
|
20
20
|
return
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
|
24
|
+
msg = <<-TEXT
|
24
25
|
No such action exists: #{controller_name}##{action_name}.
|
25
26
|
Note: this application uses the whitelisted_actions plugin,
|
26
27
|
you might have to use the 'actions' method to whitelist your actions.
|
27
28
|
TEXT
|
29
|
+
|
30
|
+
logger.warn msg
|
31
|
+
error 404, msg
|
28
32
|
end
|
29
33
|
end
|
30
34
|
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module ActiveRecord::Extension::CachedColumn
|
2
|
+
DEFAULTS = {
|
3
|
+
:time_to_live => 5.minutes
|
4
|
+
}
|
5
|
+
|
6
|
+
def self.included(klass)
|
7
|
+
klass.extend ClassMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
#
|
12
|
+
# cached_column :name, :time_to_live => 5.minutes
|
13
|
+
def cached_column(name, options = ActiveRecord::Extension::CachedColumn::DEFAULTS, &block)
|
14
|
+
#
|
15
|
+
# create the "#{name}_updated_at_column"
|
16
|
+
lite_table do
|
17
|
+
datetime "#{name}_updated_at"
|
18
|
+
end
|
19
|
+
|
20
|
+
define_method(name) do
|
21
|
+
read_cached_column(name, options, Proc.new)
|
22
|
+
end
|
23
|
+
|
24
|
+
define_method("#{name}!") do
|
25
|
+
write_attribute "#{name}_updated_at", nil
|
26
|
+
self.send name
|
27
|
+
end
|
28
|
+
|
29
|
+
define_method("#{name}=") do |v|
|
30
|
+
write_cached_column(name, v)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def write_cached_column(name, value)
|
38
|
+
write_attribute name, value
|
39
|
+
write_attribute "#{name}_updated_at", Time.now
|
40
|
+
end
|
41
|
+
|
42
|
+
def read_cached_column(name, options, proc)
|
43
|
+
updated_at = self.send("#{name}_updated_at")
|
44
|
+
r = if updated_at && updated_at + options[:time_to_live] > Time.now
|
45
|
+
read_attribute(name)
|
46
|
+
else
|
47
|
+
value = if proc.arity <= 0 then proc.bind(self).call
|
48
|
+
elsif proc.arity == 1 then proc.call(self)
|
49
|
+
else raise "Unsupported # of block parameters"
|
50
|
+
end
|
51
|
+
|
52
|
+
update_attributes! name => value
|
53
|
+
value
|
54
|
+
end
|
55
|
+
|
56
|
+
r = r.slop if r.respond_to?(:slop)
|
57
|
+
r
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
ActiveRecord::Base.send :include, ActiveRecord::Extension::CachedColumn
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module ActiveRecord::Extension::CachedColumn::Etest
|
2
|
+
def setup
|
3
|
+
require "timecop"
|
4
|
+
end
|
5
|
+
|
6
|
+
class X < ActiveRecord::Base
|
7
|
+
lite_table do
|
8
|
+
string :something
|
9
|
+
string :bigger
|
10
|
+
string :bigger_w_param
|
11
|
+
end
|
12
|
+
|
13
|
+
cached_column :something do
|
14
|
+
$something = $something + 1
|
15
|
+
"something-big"
|
16
|
+
end
|
17
|
+
|
18
|
+
cached_column :bigger, :time_to_live => 1.day do
|
19
|
+
$something = $something + 1
|
20
|
+
"something-bigger"
|
21
|
+
end
|
22
|
+
|
23
|
+
cached_column :bigger_w_param do |rec|
|
24
|
+
rec.class.name
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_something
|
29
|
+
$something = 0
|
30
|
+
x = X.create!
|
31
|
+
assert_equal(0, $something)
|
32
|
+
assert_equal("something-big", x.something)
|
33
|
+
assert_equal(1, $something)
|
34
|
+
assert_equal("something-big", x.something)
|
35
|
+
assert_equal(1, $something)
|
36
|
+
|
37
|
+
Timecop.travel(360.seconds) do
|
38
|
+
assert_equal(1, $something)
|
39
|
+
assert_equal("something-big", x.something)
|
40
|
+
assert_equal(2, $something)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_w_new_record
|
45
|
+
$something = 0
|
46
|
+
x = X.new
|
47
|
+
assert_equal(0, $something)
|
48
|
+
assert_equal("something-big", x.something)
|
49
|
+
assert_equal(1, $something)
|
50
|
+
assert_equal("something-big", x.something)
|
51
|
+
assert_equal(1, $something)
|
52
|
+
|
53
|
+
Timecop.travel(360.seconds) do
|
54
|
+
assert_equal(1, $something)
|
55
|
+
assert_equal("something-big", x.something)
|
56
|
+
assert_equal(2, $something)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_time_to_live
|
61
|
+
$something = 0
|
62
|
+
x = X.create!
|
63
|
+
assert_equal(0, $something)
|
64
|
+
assert_equal("something-bigger", x.bigger)
|
65
|
+
assert_equal(1, $something)
|
66
|
+
|
67
|
+
Timecop.travel(Time.now + 6.minutes) do
|
68
|
+
assert_equal(1, $something)
|
69
|
+
assert_equal("something-bigger", x.bigger)
|
70
|
+
assert_equal(1, $something)
|
71
|
+
end
|
72
|
+
|
73
|
+
Timecop.travel(Time.now + 25.hours) do
|
74
|
+
assert_equal(1, $something)
|
75
|
+
assert_equal("something-bigger", x.bigger)
|
76
|
+
assert_equal(2, $something)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
def test_bigger_w_params
|
82
|
+
$something = 0
|
83
|
+
x = X.create!
|
84
|
+
assert_equal("ActiveRecord::Extension::CachedColumn::Etest::X", x.bigger_w_param)
|
85
|
+
end
|
86
|
+
end
|
@@ -11,19 +11,21 @@ module ActiveRecord::LiteTable
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def column(name, type, opts = {})
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
klass.silence do
|
15
|
+
if !existing_column = klass.columns_hash[name.to_s]
|
16
|
+
index_opt = opts.delete :index
|
17
|
+
klass.connection.add_column(klass.table_name, name, type, opts)
|
18
|
+
klass.reset_column_information
|
19
|
+
|
20
|
+
index(name, :unique => (index_opt == :unique)) if index_opt
|
21
|
+
return
|
22
|
+
end
|
23
|
+
|
24
|
+
return if existing_column.type == type
|
25
|
+
|
26
|
+
raise ColumnTypeMismatch,
|
27
|
+
"Column type mismatch on #{klass}##{name}: is #{existing_column.type}, but should be #{type}"
|
21
28
|
end
|
22
|
-
|
23
|
-
return if existing_column.type == type
|
24
|
-
|
25
|
-
raise ColumnTypeMismatch,
|
26
|
-
"Column type mismatch on #{klass}##{name}: is #{existing_column.type}, but should be #{type}"
|
27
29
|
end
|
28
30
|
|
29
31
|
def timestamps(*cols)
|
@@ -55,7 +57,9 @@ module ActiveRecord::LiteTable
|
|
55
57
|
|
56
58
|
def index(column_name, options={})
|
57
59
|
begin
|
58
|
-
klass.
|
60
|
+
klass.silence do
|
61
|
+
klass.connection.add_index klass.table_name, column_name, options
|
62
|
+
end
|
59
63
|
rescue
|
60
64
|
# TODO: It would be *great* to have a unique exception type here!
|
61
65
|
# But even in this case we have to check the options for identity!
|
@@ -0,0 +1 @@
|
|
1
|
+
test.sqlite3
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ActiveRecord::Extension::WithScope
|
2
|
+
|
3
|
+
def self.included(klass)
|
4
|
+
#
|
5
|
+
# add a custom scope.
|
6
|
+
klass.named_scope :with, lambda { |*args| ActiveRecord::Extension::WithScope.options(*args) }
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.options(*args)
|
10
|
+
options = args.extract_options!
|
11
|
+
if options[:conditions] && !args.empty?
|
12
|
+
raise "Cannot have multiple condition entries"
|
13
|
+
end
|
14
|
+
|
15
|
+
unless args.empty?
|
16
|
+
options = { :conditions => args }.update(options)
|
17
|
+
end
|
18
|
+
|
19
|
+
options
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
ActiveRecord::Base.send :include, ActiveRecord::Extension::WithScope
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "cgi"
|
2
|
+
|
3
|
+
class CGI
|
4
|
+
def self.url_for(*args)
|
5
|
+
opts = case args.last
|
6
|
+
when Array, Hash then args.pop
|
7
|
+
else {}
|
8
|
+
end
|
9
|
+
|
10
|
+
url_base = args.map do |arg|
|
11
|
+
arg.gsub(/(^\/)|(\/$)/, "")
|
12
|
+
end.join("/")
|
13
|
+
|
14
|
+
return url_base if opts.empty?
|
15
|
+
|
16
|
+
url_base += url_base.index("?") ? "&" : "?"
|
17
|
+
|
18
|
+
url_base + opts.map do |k,v|
|
19
|
+
p = escape(k.to_s)
|
20
|
+
p += "=" + escape(v.to_s) if v
|
21
|
+
p
|
22
|
+
end.join("&")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module CGI::Etest
|
27
|
+
def test_url_for
|
28
|
+
assert_equal "http://ix.de", CGI.url_for("http://ix.de")
|
29
|
+
assert_equal "http://ix.de?a", CGI.url_for("http://ix.de", :a => nil)
|
30
|
+
assert_equal "http://ix.de?a", CGI.url_for("http://ix.de", [ :a ])
|
31
|
+
assert_equal "http://ix.de?a=1", CGI.url_for("http://ix.de", :a => 1 )
|
32
|
+
assert_equal "http://ix.de?a=1", CGI.url_for("http://ix.de", [ [ :a, 1 ]] )
|
33
|
+
assert_equal "http://ix.de?a=1&b=bb", CGI.url_for("http://ix.de", [ [ :a, 1 ], [ :b, :bb ]] )
|
34
|
+
assert_equal "http://ix.de?a=b%3D1", CGI.url_for("http://ix.de", :a => "b=1" )
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_url_for_merging
|
38
|
+
assert_equal "http://ix.de/a/b", CGI.url_for("http://ix.de", "a", "b")
|
39
|
+
assert_equal "http://ix.de/a/b", CGI.url_for("http://ix.de/", "a/", "b")
|
40
|
+
assert_equal "http://ix.de/a/b", CGI.url_for("http://ix.de/", "/a/", "/b/")
|
41
|
+
assert_equal "http://ix.de//x/y", CGI.url_for("http://ix.de//", "/x/y")
|
42
|
+
assert_equal "http://ix.de//x///y", CGI.url_for("http://ix.de//", "/x///y")
|
43
|
+
end
|
44
|
+
end if VEX_TEST == "base"
|
data/lib/vex/base/hash/slop.rb
CHANGED
@@ -35,7 +35,7 @@ class Hash
|
|
35
35
|
# Return true if the entry exists and evaluates to false
|
36
36
|
# Return the entry otherwise.
|
37
37
|
key = lookup_sloppy_key($1)
|
38
|
-
return
|
38
|
+
return nil if !key?(key)
|
39
39
|
return (self[key] || true).slop!
|
40
40
|
else
|
41
41
|
# fetch the entry, if it exists, or raise an IndexError
|
@@ -78,6 +78,8 @@ end
|
|
78
78
|
class Object
|
79
79
|
def slop
|
80
80
|
dup.slop!
|
81
|
+
rescue TypeError # e.g. "Can't dup NilClass"
|
82
|
+
self
|
81
83
|
end
|
82
84
|
|
83
85
|
def slop!
|
@@ -112,7 +114,7 @@ module Hash::Slop::Etest
|
|
112
114
|
assert_equal true, h.a?
|
113
115
|
assert_equal true, h.b?
|
114
116
|
assert_equal 1, h.c?
|
115
|
-
assert_equal
|
117
|
+
assert_equal nil, h.d?
|
116
118
|
|
117
119
|
assert_equal nil, h.a
|
118
120
|
assert_equal false, h.b
|
data/lib/vex/base/local_conf.rb
CHANGED
@@ -8,18 +8,13 @@ class LocalConf < Hash
|
|
8
8
|
return if r1 || r2
|
9
9
|
|
10
10
|
raise Errno::ENOENT,
|
11
|
-
"Missing configuration file #{
|
11
|
+
"Missing configuration file #{App.root}/config/#{file.sub(/\.yml$/, "")}{.defaults}.yml}"
|
12
12
|
end
|
13
13
|
|
14
14
|
private
|
15
15
|
|
16
|
-
def fullpath(file)
|
17
|
-
return file if file.starts_with?("/")
|
18
|
-
"#{App.root}/config/#{file}"
|
19
|
-
end
|
20
|
-
|
21
16
|
def load(file)
|
22
|
-
data = YAML::load_file(
|
17
|
+
data = YAML::load_file("#{App.root}/config/#{file}")
|
23
18
|
|
24
19
|
data.each { |k,v| update k.to_sym => v }
|
25
20
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Hash
|
2
|
+
alias :delete_single :delete
|
3
|
+
|
4
|
+
def delete_multi(a0, *extras, &block)
|
5
|
+
if extras.empty? || block_given?
|
6
|
+
delete_single a0, *extras, &block
|
7
|
+
else
|
8
|
+
r = [ delete_single(a0) ]
|
9
|
+
extras.each do |arg|
|
10
|
+
r.push delete_single(arg)
|
11
|
+
end
|
12
|
+
r
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
alias :delete :delete_multi
|
17
|
+
end
|
data/vex/gem.rake
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
def sys(*args)
|
2
|
+
STDERR.puts "#{args.join(" ")}"
|
3
|
+
system *args
|
4
|
+
end
|
5
|
+
|
6
|
+
namespace :gem do
|
7
|
+
task :build => :spec do
|
8
|
+
options = []
|
9
|
+
sys "gem build .gemspec #{options.join(" ")} && mkdir -p pkg && mv *.gem pkg"
|
10
|
+
end
|
11
|
+
|
12
|
+
task :spec do
|
13
|
+
File.open ".gemspec", "w" do |file|
|
14
|
+
file.write <<-TXT
|
15
|
+
require "vex/gem"
|
16
|
+
Gem.spec File.dirname(__FILE__)
|
17
|
+
TXT
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
task :install => :build do
|
22
|
+
file = Dir.glob("pkg/*.gem").sort.last
|
23
|
+
sys "gem install #{file}"
|
24
|
+
end
|
25
|
+
|
26
|
+
task :push => :build do
|
27
|
+
file = Dir.glob("pkg/*.gem").sort.last
|
28
|
+
puts "To push the gem to gemcutter please run"
|
29
|
+
puts
|
30
|
+
puts "\tgem push #{file}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "Build gem"
|
35
|
+
# task :gem => %w(test gem:install)
|
36
|
+
task :gem => %w(gem:install gem:push)
|
data/vex/gem.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
module Gem
|
2
|
+
(class << self; self; end).class_eval do
|
3
|
+
def default_attributes
|
4
|
+
%w(name version date files executables)
|
5
|
+
end
|
6
|
+
|
7
|
+
def set_root(root)
|
8
|
+
@root = File.expand_path(root)
|
9
|
+
@name = File.basename(@root)
|
10
|
+
@conf ||= YAML.load File.read("#{@root}/gem.yml")
|
11
|
+
@attributes ||= (default_attributes + @conf.keys.map(&:to_s)).uniq
|
12
|
+
end
|
13
|
+
|
14
|
+
# attr_reader :root, :conf, :attributes,
|
15
|
+
attr_reader :name
|
16
|
+
|
17
|
+
def attribute(name)
|
18
|
+
if @conf.key?(name) && !%w(dependencies).include?(name)
|
19
|
+
@conf[name]
|
20
|
+
else
|
21
|
+
self.send(name)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
#
|
26
|
+
# create a new Gem::Specification object for this gem.
|
27
|
+
def spec(root)
|
28
|
+
self.set_root root
|
29
|
+
|
30
|
+
Gem::Specification.new do |s|
|
31
|
+
@attributes.each do |attr|
|
32
|
+
v = attribute(attr)
|
33
|
+
next if v.nil?
|
34
|
+
|
35
|
+
log attr, v
|
36
|
+
|
37
|
+
s.send attr + "=", v
|
38
|
+
end
|
39
|
+
|
40
|
+
%w(pre_uninstall post_install).each do |hook|
|
41
|
+
next unless File.exists?("#{root}/hooks/#{hook}.rb")
|
42
|
+
log hook, "yes"
|
43
|
+
Gem.send(hook) {
|
44
|
+
load "hooks/#{hook}.rb"
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def log(attr, v)
|
51
|
+
v = case attr
|
52
|
+
when "files" then "#{v.length} files"
|
53
|
+
else v.inspect
|
54
|
+
end
|
55
|
+
|
56
|
+
STDERR.puts "#{"%20s" % attr}:\t#{v}"
|
57
|
+
end
|
58
|
+
|
59
|
+
def dependencies
|
60
|
+
return nil unless @conf["dependencies"]
|
61
|
+
|
62
|
+
@conf["dependencies"].map do |d|
|
63
|
+
Gem::Dependency.new d, ">= 0"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def head(file)
|
68
|
+
File.open(file) do |f|
|
69
|
+
f.readline
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def executables
|
74
|
+
r = Dir.glob("#{@root}/bin/**/*").map do |file|
|
75
|
+
next unless head(file) =~ /^#!/
|
76
|
+
file[@root.length + 5 .. -1]
|
77
|
+
end.compact
|
78
|
+
|
79
|
+
return nil if r.empty?
|
80
|
+
r
|
81
|
+
end
|
82
|
+
|
83
|
+
#
|
84
|
+
# get files from git
|
85
|
+
def files
|
86
|
+
r = `git ls-files`.split("\n")
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# return the date
|
91
|
+
def date
|
92
|
+
Date.today.to_s
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 3
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 6
|
9
|
+
- 2
|
10
|
+
version: 0.6.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- pboy
|
@@ -15,11 +15,11 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-07-03 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
22
|
+
name: etest
|
23
23
|
prerelease: false
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
type: :runtime
|
34
34
|
version_requirements: *id001
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
36
|
+
name: nokogiri
|
37
37
|
prerelease: false
|
38
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
@@ -47,7 +47,7 @@ dependencies:
|
|
47
47
|
type: :runtime
|
48
48
|
version_requirements: *id002
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
|
-
name:
|
50
|
+
name: sanitize
|
51
51
|
prerelease: false
|
52
52
|
requirement: &id003 !ruby/object:Gem::Requirement
|
53
53
|
none: false
|
@@ -61,7 +61,7 @@ dependencies:
|
|
61
61
|
type: :runtime
|
62
62
|
version_requirements: *id003
|
63
63
|
- !ruby/object:Gem::Dependency
|
64
|
-
name:
|
64
|
+
name: htmlentities
|
65
65
|
prerelease: false
|
66
66
|
requirement: &id004 !ruby/object:Gem::Requirement
|
67
67
|
none: false
|
@@ -75,7 +75,7 @@ dependencies:
|
|
75
75
|
type: :runtime
|
76
76
|
version_requirements: *id004
|
77
77
|
- !ruby/object:Gem::Dependency
|
78
|
-
name:
|
78
|
+
name: json
|
79
79
|
prerelease: false
|
80
80
|
requirement: &id005 !ruby/object:Gem::Requirement
|
81
81
|
none: false
|
@@ -94,102 +94,16 @@ executables: []
|
|
94
94
|
|
95
95
|
extensions: []
|
96
96
|
|
97
|
-
extra_rdoc_files:
|
98
|
-
|
99
|
-
- lib/nokogiri/nokogiri_ext.rb
|
100
|
-
- lib/vex.rb
|
101
|
-
- lib/vex/action_controller.rb
|
102
|
-
- lib/vex/action_controller/error.rb
|
103
|
-
- lib/vex/action_controller/output_logging.rb
|
104
|
-
- lib/vex/action_controller/partial_helper.rb
|
105
|
-
- lib/vex/action_controller/verify_action.rb
|
106
|
-
- lib/vex/action_controller/verify_hostname.rb
|
107
|
-
- lib/vex/action_controller/whitelisted_actions.rb
|
108
|
-
- lib/vex/active_record.rb
|
109
|
-
- lib/vex/active_record/__init__.rb
|
110
|
-
- lib/vex/active_record/advisory_lock.rb
|
111
|
-
- lib/vex/active_record/advisory_lock/mysql_adapter.rb
|
112
|
-
- lib/vex/active_record/advisory_lock/sqlite_adapter.rb
|
113
|
-
- lib/vex/active_record/belongs_to_many.rb
|
114
|
-
- lib/vex/active_record/custom_validations.rb
|
115
|
-
- lib/vex/active_record/find_by_extension.rb
|
116
|
-
- lib/vex/active_record/gem.rb
|
117
|
-
- lib/vex/active_record/lite_table.rb
|
118
|
-
- lib/vex/active_record/lite_view.rb
|
119
|
-
- lib/vex/active_record/mass_load.rb
|
120
|
-
- lib/vex/active_record/mysql_backup.rb
|
121
|
-
- lib/vex/active_record/plugins/default_value_for/LICENSE.TXT
|
122
|
-
- lib/vex/active_record/plugins/default_value_for/README.rdoc
|
123
|
-
- lib/vex/active_record/plugins/default_value_for/Rakefile
|
124
|
-
- lib/vex/active_record/plugins/default_value_for/init.rb
|
125
|
-
- lib/vex/active_record/plugins/default_value_for/test.rb
|
126
|
-
- lib/vex/active_record/random_id.rb
|
127
|
-
- lib/vex/active_record/resolver.rb
|
128
|
-
- lib/vex/active_record/serialize_hash.rb
|
129
|
-
- lib/vex/active_record/to_html.rb
|
130
|
-
- lib/vex/active_record/validate.rb
|
131
|
-
- lib/vex/active_record/validation_error_ext.rb
|
132
|
-
- lib/vex/base.rb
|
133
|
-
- lib/vex/base/app.rb
|
134
|
-
- lib/vex/base/argv.rb
|
135
|
-
- lib/vex/base/array/at_random.rb
|
136
|
-
- lib/vex/base/array/avg.rb
|
137
|
-
- lib/vex/base/array/cross.rb
|
138
|
-
- lib/vex/base/array/each_batch.rb
|
139
|
-
- lib/vex/base/array/parallel_map.rb
|
140
|
-
- lib/vex/base/deprecation.rb
|
141
|
-
- lib/vex/base/enumerable/deep.rb
|
142
|
-
- lib/vex/base/enumerable/enumerable_ext.rb
|
143
|
-
- lib/vex/base/enumerable/progress.rb
|
144
|
-
- lib/vex/base/filesystem/fast_copy.rb
|
145
|
-
- lib/vex/base/filesystem/grep.rb
|
146
|
-
- lib/vex/base/filesystem/lock.rb
|
147
|
-
- lib/vex/base/filesystem/lock.rb.test.lck
|
148
|
-
- lib/vex/base/filesystem/lock.rb.test.pid
|
149
|
-
- lib/vex/base/filesystem/make_dirs.rb
|
150
|
-
- lib/vex/base/filesystem/parse_filename.rb
|
151
|
-
- lib/vex/base/filesystem/tmp_file.rb
|
152
|
-
- lib/vex/base/filesystem/write.rb
|
153
|
-
- lib/vex/base/hash/compact.rb
|
154
|
-
- lib/vex/base/hash/cross.rb
|
155
|
-
- lib/vex/base/hash/ensure_keys.rb
|
156
|
-
- lib/vex/base/hash/extract.rb
|
157
|
-
- lib/vex/base/hash/extras.rb
|
158
|
-
- lib/vex/base/hash/inspect.rb
|
159
|
-
- lib/vex/base/hash/slop.rb
|
160
|
-
- lib/vex/base/invalid_argument/invalid_argument.rb
|
161
|
-
- lib/vex/base/local_conf.rb
|
162
|
-
- lib/vex/base/net/http_ext.rb
|
163
|
-
- lib/vex/base/net/socket_ext.rb
|
164
|
-
- lib/vex/base/object/in.rb
|
165
|
-
- lib/vex/base/object/insp.rb
|
166
|
-
- lib/vex/base/object/multiple_attributes.rb
|
167
|
-
- lib/vex/base/object/singleton_methods.rb
|
168
|
-
- lib/vex/base/object/with_benchmark.rb
|
169
|
-
- lib/vex/base/range_array.rb
|
170
|
-
- lib/vex/base/range_ext.rb
|
171
|
-
- lib/vex/base/safe_token.rb
|
172
|
-
- lib/vex/base/string/iconvert.rb
|
173
|
-
- lib/vex/base/string/string_ext.rb
|
174
|
-
- lib/vex/base/system.rb
|
175
|
-
- lib/vex/base/thread/deferred.rb
|
176
|
-
- lib/vex/base/thread/sleep.rb
|
177
|
-
- lib/vex/base/time/date_ext.rb
|
178
|
-
- lib/vex/boot.rb
|
179
|
-
- lib/vex/boot/array.rb
|
180
|
-
- lib/vex/boot/blank.rb
|
181
|
-
- lib/vex/boot/string.rb
|
182
|
-
- tasks/echoe.rake
|
183
|
-
- tasks/validate_db.rake
|
97
|
+
extra_rdoc_files: []
|
98
|
+
|
184
99
|
files:
|
100
|
+
- .gitignore
|
185
101
|
- CHANGELOG
|
186
102
|
- Manifest
|
187
103
|
- NOTICE.txt
|
188
104
|
- Rakefile
|
189
105
|
- VERSION
|
190
|
-
-
|
191
|
-
- config/dependencies.rb
|
192
|
-
- config/gem.yml
|
106
|
+
- gem.yml
|
193
107
|
- init.rb
|
194
108
|
- lib/nokogiri/nokogiri_ext.rb
|
195
109
|
- lib/vex.rb
|
@@ -206,13 +120,17 @@ files:
|
|
206
120
|
- lib/vex/active_record/advisory_lock/mysql_adapter.rb
|
207
121
|
- lib/vex/active_record/advisory_lock/sqlite_adapter.rb
|
208
122
|
- lib/vex/active_record/belongs_to_many.rb
|
123
|
+
- lib/vex/active_record/cached_column.rb
|
124
|
+
- lib/vex/active_record/cached_column/etest.rb
|
209
125
|
- lib/vex/active_record/custom_validations.rb
|
126
|
+
- lib/vex/active_record/errors.rb
|
210
127
|
- lib/vex/active_record/find_by_extension.rb
|
211
128
|
- lib/vex/active_record/gem.rb
|
212
129
|
- lib/vex/active_record/lite_table.rb
|
213
130
|
- lib/vex/active_record/lite_view.rb
|
214
131
|
- lib/vex/active_record/mass_load.rb
|
215
132
|
- lib/vex/active_record/mysql_backup.rb
|
133
|
+
- lib/vex/active_record/plugins/default_value_for/.gitignore
|
216
134
|
- lib/vex/active_record/plugins/default_value_for/LICENSE.TXT
|
217
135
|
- lib/vex/active_record/plugins/default_value_for/README.rdoc
|
218
136
|
- lib/vex/active_record/plugins/default_value_for/Rakefile
|
@@ -224,6 +142,7 @@ files:
|
|
224
142
|
- lib/vex/active_record/to_html.rb
|
225
143
|
- lib/vex/active_record/validate.rb
|
226
144
|
- lib/vex/active_record/validation_error_ext.rb
|
145
|
+
- lib/vex/active_record/with_scope.rb
|
227
146
|
- lib/vex/base.rb
|
228
147
|
- lib/vex/base/app.rb
|
229
148
|
- lib/vex/base/argv.rb
|
@@ -232,6 +151,7 @@ files:
|
|
232
151
|
- lib/vex/base/array/cross.rb
|
233
152
|
- lib/vex/base/array/each_batch.rb
|
234
153
|
- lib/vex/base/array/parallel_map.rb
|
154
|
+
- lib/vex/base/cgi_ext.rb
|
235
155
|
- lib/vex/base/deprecation.rb
|
236
156
|
- lib/vex/base/enumerable/deep.rb
|
237
157
|
- lib/vex/base/enumerable/enumerable_ext.rb
|
@@ -239,8 +159,6 @@ files:
|
|
239
159
|
- lib/vex/base/filesystem/fast_copy.rb
|
240
160
|
- lib/vex/base/filesystem/grep.rb
|
241
161
|
- lib/vex/base/filesystem/lock.rb
|
242
|
-
- lib/vex/base/filesystem/lock.rb.test.lck
|
243
|
-
- lib/vex/base/filesystem/lock.rb.test.pid
|
244
162
|
- lib/vex/base/filesystem/make_dirs.rb
|
245
163
|
- lib/vex/base/filesystem/parse_filename.rb
|
246
164
|
- lib/vex/base/filesystem/tmp_file.rb
|
@@ -260,7 +178,6 @@ files:
|
|
260
178
|
- lib/vex/base/object/insp.rb
|
261
179
|
- lib/vex/base/object/multiple_attributes.rb
|
262
180
|
- lib/vex/base/object/singleton_methods.rb
|
263
|
-
- lib/vex/base/object/with_benchmark.rb
|
264
181
|
- lib/vex/base/range_array.rb
|
265
182
|
- lib/vex/base/range_ext.rb
|
266
183
|
- lib/vex/base/safe_token.rb
|
@@ -273,11 +190,11 @@ files:
|
|
273
190
|
- lib/vex/boot.rb
|
274
191
|
- lib/vex/boot/array.rb
|
275
192
|
- lib/vex/boot/blank.rb
|
193
|
+
- lib/vex/boot/hash.rb
|
276
194
|
- lib/vex/boot/string.rb
|
277
195
|
- migration/create_request_log.rb
|
278
196
|
- script/console
|
279
197
|
- script/rebuild
|
280
|
-
- tasks/echoe.rake
|
281
198
|
- tasks/validate_db.rake
|
282
199
|
- test/ar.rb
|
283
200
|
- test/auto.rb
|
@@ -287,17 +204,16 @@ files:
|
|
287
204
|
- test/config/local.defaults.yml
|
288
205
|
- test/config/local.yml
|
289
206
|
- test/test_helper.rb
|
290
|
-
-
|
207
|
+
- test/tmp/EMPTYDIR
|
208
|
+
- vex/gem.rake
|
209
|
+
- vex/gem.rb
|
291
210
|
has_rdoc: true
|
292
211
|
homepage: http://github.com/pboy/vex
|
293
212
|
licenses: []
|
294
213
|
|
295
214
|
post_install_message:
|
296
|
-
rdoc_options:
|
297
|
-
|
298
|
-
- --inline-source
|
299
|
-
- --title
|
300
|
-
- Vex
|
215
|
+
rdoc_options: []
|
216
|
+
|
301
217
|
require_paths:
|
302
218
|
- lib
|
303
219
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -314,17 +230,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
314
230
|
requirements:
|
315
231
|
- - ">="
|
316
232
|
- !ruby/object:Gem::Version
|
317
|
-
hash:
|
233
|
+
hash: 3
|
318
234
|
segments:
|
319
|
-
-
|
320
|
-
|
321
|
-
version: "1.2"
|
235
|
+
- 0
|
236
|
+
version: "0"
|
322
237
|
requirements: []
|
323
238
|
|
324
|
-
rubyforge_project:
|
325
|
-
rubygems_version: 1.
|
239
|
+
rubyforge_project:
|
240
|
+
rubygems_version: 1.6.2
|
326
241
|
signing_key:
|
327
242
|
specification_version: 3
|
328
243
|
summary: "Vex: some ruby extensions"
|
329
|
-
test_files:
|
330
|
-
|
244
|
+
test_files: []
|
245
|
+
|
data/config/README
DELETED
data/config/dependencies.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# require all dependent gems
|
3
|
-
require 'nokogiri' unless defined?(Nokogiri)
|
4
|
-
|
5
|
-
require 'sanitize' unless defined?(Sanitize)
|
6
|
-
require 'htmlentities' unless defined?(HtmlEntities)
|
7
|
-
require 'json' unless defined?(Json)
|
8
|
-
|
9
|
-
require 'etest' unless defined?(Etest)
|
10
|
-
|
data/config/gem.yml
DELETED
File without changes
|
@@ -1 +0,0 @@
|
|
1
|
-
25983.106710
|
@@ -1,110 +0,0 @@
|
|
1
|
-
require "benchmark"
|
2
|
-
|
3
|
-
module Object::WithBenchmark
|
4
|
-
|
5
|
-
class BenchmarkProxy
|
6
|
-
def initialize(host, *args)
|
7
|
-
@host = host
|
8
|
-
|
9
|
-
if args.length == 1 && args.first.is_a?(String)
|
10
|
-
@out, @label = nil, args.first
|
11
|
-
else
|
12
|
-
@out, @label = *args
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def report(msg)
|
19
|
-
if !@out
|
20
|
-
logger = @host.respond_to?(:logger) && @host.logger || App.logger
|
21
|
-
|
22
|
-
logger.warn(msg)
|
23
|
-
STDERR.puts(msg) if App.env == "development"
|
24
|
-
elsif @out.respond_to?(:warn)
|
25
|
-
@out.warn(msg)
|
26
|
-
elsif @out.respond_to?(:<<)
|
27
|
-
@out << "#{msg}\n"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def method_missing(*args, &block)
|
32
|
-
result = ex = nil
|
33
|
-
|
34
|
-
realtime = Benchmark.realtime do
|
35
|
-
begin
|
36
|
-
result = @host.__send__(*args, &block)
|
37
|
-
rescue
|
38
|
-
ex = $!
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
msg = "#{@label || "benchmarked"}: #{ex && "EXCEPTION #{ex} after "}#{"%.2f secs" % realtime}"
|
43
|
-
|
44
|
-
report(msg)
|
45
|
-
|
46
|
-
raise ex if ex
|
47
|
-
result
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def no_benchmark(*args, &block)
|
52
|
-
block_given? ? yield : self
|
53
|
-
end
|
54
|
-
|
55
|
-
def benchmark(*args, &block)
|
56
|
-
count = args.last.is_a?(Fixnum) ? args.pop : 1
|
57
|
-
|
58
|
-
proxy = BenchmarkProxy.new self, *args, &block
|
59
|
-
return proxy unless block_given?
|
60
|
-
return proxy.yield(&block) if count <= 1
|
61
|
-
return proxy.yield do
|
62
|
-
count.times(&block)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def yield(&block); yield; end
|
67
|
-
end
|
68
|
-
|
69
|
-
Object.send :include, Object::WithBenchmark
|
70
|
-
|
71
|
-
module Object::WithBenchmark::Etest
|
72
|
-
def test_results
|
73
|
-
App.logger.stubs(:warn).returns(nil)
|
74
|
-
|
75
|
-
assert_equal 6, "string".benchmark.length
|
76
|
-
assert_raise(NoMethodError) {
|
77
|
-
"string".benchmark.you_dont_know_me
|
78
|
-
}
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_benchmark
|
82
|
-
s = ""
|
83
|
-
assert_equal 6, "string".benchmark(s, "").length
|
84
|
-
assert s.length > 0
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_label
|
88
|
-
App.logger.stubs(:warn).returns(nil)
|
89
|
-
|
90
|
-
assert_equal 6, "string".benchmark("oh! a label!").length
|
91
|
-
end
|
92
|
-
|
93
|
-
class DL
|
94
|
-
attr :msg
|
95
|
-
def warn(s);
|
96
|
-
@msg = s
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_logger
|
101
|
-
s = "string"
|
102
|
-
|
103
|
-
def s.logger; @logger ||= DL.new; end
|
104
|
-
assert s.respond_to?(:logger)
|
105
|
-
assert s.logger.msg.blank?
|
106
|
-
|
107
|
-
assert_equal 6, s.benchmark.length
|
108
|
-
assert !s.logger.msg.blank?
|
109
|
-
end
|
110
|
-
end if VEX_TEST == "base"
|
data/tasks/echoe.rake
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
unless defined?(SKIP_ECHOE)
|
2
|
-
|
3
|
-
#
|
4
|
-
# GEM settings
|
5
|
-
#
|
6
|
-
GEM_ROOT = File.expand_path("#{File.dirname(__FILE__)}/..")
|
7
|
-
|
8
|
-
if gem_config = YAML.load(File.read("#{GEM_ROOT}/config/gem.yml"))
|
9
|
-
require 'echoe'
|
10
|
-
|
11
|
-
#
|
12
|
-
# a dependency reader
|
13
|
-
module Dependency
|
14
|
-
@@dependencies = []
|
15
|
-
|
16
|
-
def self.require(file)
|
17
|
-
@@dependencies << file
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.load
|
21
|
-
eval File.read("#{GEM_ROOT}/config/dependencies.rb"), binding
|
22
|
-
@@dependencies
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
Echoe.new(File.basename(GEM_ROOT), File.read("#{GEM_ROOT}/VERSION")) do |p|
|
27
|
-
gem_config.each do |k,v|
|
28
|
-
p.send "#{k}=",v
|
29
|
-
end
|
30
|
-
|
31
|
-
p.runtime_dependencies = Dependency.load
|
32
|
-
end
|
33
|
-
|
34
|
-
desc "Rebuild and install the gem"
|
35
|
-
task :rebuild => %w(manifest default build_gemspec package) do
|
36
|
-
gem = Dir.glob("pkg/*.gem").sort_by do |filename|
|
37
|
-
File.new(filename).mtime
|
38
|
-
end.last
|
39
|
-
|
40
|
-
puts "============================================="
|
41
|
-
puts "Installing gem..."
|
42
|
-
|
43
|
-
system "sudo gem install #{gem} --no-test --no-ri --no-rdoc > /dev/null 2>&1"
|
44
|
-
|
45
|
-
puts ""
|
46
|
-
puts "I built and installed the gem for you. To upload, run "
|
47
|
-
puts
|
48
|
-
puts " gem push #{gem}"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
data/vex.gemspec
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
Gem::Specification.new do |s|
|
4
|
-
s.name = %q{vex}
|
5
|
-
s.version = "0.4.4"
|
6
|
-
|
7
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = ["pboy"]
|
9
|
-
s.date = %q{2010-06-13}
|
10
|
-
s.description = %q{Vex: some ruby extensions}
|
11
|
-
s.email = %q{eno-pboy@open-lab.org}
|
12
|
-
s.extra_rdoc_files = ["CHANGELOG", "lib/nokogiri/nokogiri_ext.rb", "lib/vex.rb", "lib/vex/action_controller.rb", "lib/vex/action_controller/error.rb", "lib/vex/action_controller/output_logging.rb", "lib/vex/action_controller/partial_helper.rb", "lib/vex/action_controller/verify_action.rb", "lib/vex/action_controller/verify_hostname.rb", "lib/vex/action_controller/whitelisted_actions.rb", "lib/vex/active_record.rb", "lib/vex/active_record/__init__.rb", "lib/vex/active_record/advisory_lock.rb", "lib/vex/active_record/advisory_lock/mysql_adapter.rb", "lib/vex/active_record/advisory_lock/sqlite_adapter.rb", "lib/vex/active_record/belongs_to_many.rb", "lib/vex/active_record/custom_validations.rb", "lib/vex/active_record/find_by_extension.rb", "lib/vex/active_record/gem.rb", "lib/vex/active_record/lite_table.rb", "lib/vex/active_record/lite_view.rb", "lib/vex/active_record/mass_load.rb", "lib/vex/active_record/mysql_backup.rb", "lib/vex/active_record/plugins/default_value_for/LICENSE.TXT", "lib/vex/active_record/plugins/default_value_for/README.rdoc", "lib/vex/active_record/plugins/default_value_for/Rakefile", "lib/vex/active_record/plugins/default_value_for/init.rb", "lib/vex/active_record/plugins/default_value_for/test.rb", "lib/vex/active_record/random_id.rb", "lib/vex/active_record/resolver.rb", "lib/vex/active_record/serialize_hash.rb", "lib/vex/active_record/to_html.rb", "lib/vex/active_record/validate.rb", "lib/vex/active_record/validation_error_ext.rb", "lib/vex/base.rb", "lib/vex/base/app.rb", "lib/vex/base/argv.rb", "lib/vex/base/array/at_random.rb", "lib/vex/base/array/avg.rb", "lib/vex/base/array/cross.rb", "lib/vex/base/array/each_batch.rb", "lib/vex/base/array/parallel_map.rb", "lib/vex/base/deprecation.rb", "lib/vex/base/enumerable/deep.rb", "lib/vex/base/enumerable/enumerable_ext.rb", "lib/vex/base/enumerable/progress.rb", "lib/vex/base/filesystem/fast_copy.rb", "lib/vex/base/filesystem/grep.rb", "lib/vex/base/filesystem/lock.rb", "lib/vex/base/filesystem/lock.rb.test.lck", "lib/vex/base/filesystem/lock.rb.test.pid", "lib/vex/base/filesystem/make_dirs.rb", "lib/vex/base/filesystem/parse_filename.rb", "lib/vex/base/filesystem/tmp_file.rb", "lib/vex/base/filesystem/write.rb", "lib/vex/base/hash/compact.rb", "lib/vex/base/hash/cross.rb", "lib/vex/base/hash/ensure_keys.rb", "lib/vex/base/hash/extract.rb", "lib/vex/base/hash/extras.rb", "lib/vex/base/hash/inspect.rb", "lib/vex/base/hash/slop.rb", "lib/vex/base/invalid_argument/invalid_argument.rb", "lib/vex/base/local_conf.rb", "lib/vex/base/net/http_ext.rb", "lib/vex/base/net/socket_ext.rb", "lib/vex/base/object/in.rb", "lib/vex/base/object/insp.rb", "lib/vex/base/object/multiple_attributes.rb", "lib/vex/base/object/singleton_methods.rb", "lib/vex/base/object/with_benchmark.rb", "lib/vex/base/range_array.rb", "lib/vex/base/range_ext.rb", "lib/vex/base/safe_token.rb", "lib/vex/base/string/iconvert.rb", "lib/vex/base/string/string_ext.rb", "lib/vex/base/system.rb", "lib/vex/base/thread/deferred.rb", "lib/vex/base/thread/sleep.rb", "lib/vex/base/time/date_ext.rb", "lib/vex/boot.rb", "lib/vex/boot/array.rb", "lib/vex/boot/blank.rb", "lib/vex/boot/string.rb", "tasks/echoe.rake", "tasks/validate_db.rake"]
|
13
|
-
s.files = ["CHANGELOG", "Manifest", "NOTICE.txt", "Rakefile", "VERSION", "config/README", "config/dependencies.rb", "config/gem.yml", "init.rb", "lib/nokogiri/nokogiri_ext.rb", "lib/vex.rb", "lib/vex/action_controller.rb", "lib/vex/action_controller/error.rb", "lib/vex/action_controller/output_logging.rb", "lib/vex/action_controller/partial_helper.rb", "lib/vex/action_controller/verify_action.rb", "lib/vex/action_controller/verify_hostname.rb", "lib/vex/action_controller/whitelisted_actions.rb", "lib/vex/active_record.rb", "lib/vex/active_record/__init__.rb", "lib/vex/active_record/advisory_lock.rb", "lib/vex/active_record/advisory_lock/mysql_adapter.rb", "lib/vex/active_record/advisory_lock/sqlite_adapter.rb", "lib/vex/active_record/belongs_to_many.rb", "lib/vex/active_record/custom_validations.rb", "lib/vex/active_record/find_by_extension.rb", "lib/vex/active_record/gem.rb", "lib/vex/active_record/lite_table.rb", "lib/vex/active_record/lite_view.rb", "lib/vex/active_record/mass_load.rb", "lib/vex/active_record/mysql_backup.rb", "lib/vex/active_record/plugins/default_value_for/LICENSE.TXT", "lib/vex/active_record/plugins/default_value_for/README.rdoc", "lib/vex/active_record/plugins/default_value_for/Rakefile", "lib/vex/active_record/plugins/default_value_for/init.rb", "lib/vex/active_record/plugins/default_value_for/test.rb", "lib/vex/active_record/random_id.rb", "lib/vex/active_record/resolver.rb", "lib/vex/active_record/serialize_hash.rb", "lib/vex/active_record/to_html.rb", "lib/vex/active_record/validate.rb", "lib/vex/active_record/validation_error_ext.rb", "lib/vex/base.rb", "lib/vex/base/app.rb", "lib/vex/base/argv.rb", "lib/vex/base/array/at_random.rb", "lib/vex/base/array/avg.rb", "lib/vex/base/array/cross.rb", "lib/vex/base/array/each_batch.rb", "lib/vex/base/array/parallel_map.rb", "lib/vex/base/deprecation.rb", "lib/vex/base/enumerable/deep.rb", "lib/vex/base/enumerable/enumerable_ext.rb", "lib/vex/base/enumerable/progress.rb", "lib/vex/base/filesystem/fast_copy.rb", "lib/vex/base/filesystem/grep.rb", "lib/vex/base/filesystem/lock.rb", "lib/vex/base/filesystem/lock.rb.test.lck", "lib/vex/base/filesystem/lock.rb.test.pid", "lib/vex/base/filesystem/make_dirs.rb", "lib/vex/base/filesystem/parse_filename.rb", "lib/vex/base/filesystem/tmp_file.rb", "lib/vex/base/filesystem/write.rb", "lib/vex/base/hash/compact.rb", "lib/vex/base/hash/cross.rb", "lib/vex/base/hash/ensure_keys.rb", "lib/vex/base/hash/extract.rb", "lib/vex/base/hash/extras.rb", "lib/vex/base/hash/inspect.rb", "lib/vex/base/hash/slop.rb", "lib/vex/base/invalid_argument/invalid_argument.rb", "lib/vex/base/local_conf.rb", "lib/vex/base/net/http_ext.rb", "lib/vex/base/net/socket_ext.rb", "lib/vex/base/object/in.rb", "lib/vex/base/object/insp.rb", "lib/vex/base/object/multiple_attributes.rb", "lib/vex/base/object/singleton_methods.rb", "lib/vex/base/object/with_benchmark.rb", "lib/vex/base/range_array.rb", "lib/vex/base/range_ext.rb", "lib/vex/base/safe_token.rb", "lib/vex/base/string/iconvert.rb", "lib/vex/base/string/string_ext.rb", "lib/vex/base/system.rb", "lib/vex/base/thread/deferred.rb", "lib/vex/base/thread/sleep.rb", "lib/vex/base/time/date_ext.rb", "lib/vex/boot.rb", "lib/vex/boot/array.rb", "lib/vex/boot/blank.rb", "lib/vex/boot/string.rb", "migration/create_request_log.rb", "script/console", "script/rebuild", "tasks/echoe.rake", "tasks/validate_db.rake", "test/ar.rb", "test/auto.rb", "test/base-tests/local_conf.rb", "test/base.rb", "test/boot.rb", "test/config/local.defaults.yml", "test/config/local.yml", "test/test_helper.rb", "vex.gemspec"]
|
14
|
-
s.homepage = %q{http://github.com/pboy/vex}
|
15
|
-
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Vex"]
|
16
|
-
s.require_paths = ["lib"]
|
17
|
-
s.rubyforge_project = %q{vex}
|
18
|
-
s.rubygems_version = %q{1.3.7}
|
19
|
-
s.summary = %q{Vex: some ruby extensions}
|
20
|
-
s.test_files = ["test/test_helper.rb"]
|
21
|
-
|
22
|
-
if s.respond_to? :specification_version then
|
23
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
|
-
s.specification_version = 3
|
25
|
-
|
26
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
27
|
-
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
28
|
-
s.add_runtime_dependency(%q<sanitize>, [">= 0"])
|
29
|
-
s.add_runtime_dependency(%q<htmlentities>, [">= 0"])
|
30
|
-
s.add_runtime_dependency(%q<json>, [">= 0"])
|
31
|
-
s.add_runtime_dependency(%q<etest>, [">= 0"])
|
32
|
-
else
|
33
|
-
s.add_dependency(%q<nokogiri>, [">= 0"])
|
34
|
-
s.add_dependency(%q<sanitize>, [">= 0"])
|
35
|
-
s.add_dependency(%q<htmlentities>, [">= 0"])
|
36
|
-
s.add_dependency(%q<json>, [">= 0"])
|
37
|
-
s.add_dependency(%q<etest>, [">= 0"])
|
38
|
-
end
|
39
|
-
else
|
40
|
-
s.add_dependency(%q<nokogiri>, [">= 0"])
|
41
|
-
s.add_dependency(%q<sanitize>, [">= 0"])
|
42
|
-
s.add_dependency(%q<htmlentities>, [">= 0"])
|
43
|
-
s.add_dependency(%q<json>, [">= 0"])
|
44
|
-
s.add_dependency(%q<etest>, [">= 0"])
|
45
|
-
end
|
46
|
-
end
|