ruby-nuggets 0.9.9 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- metadata +20 -324
- data/COPYING +0 -663
- data/ChangeLog +0 -7
- data/README +0 -62
- data/Rakefile +0 -47
- data/lib/nuggets.rb +0 -73
- data/lib/nuggets/all.rb +0 -36
- data/lib/nuggets/all_mixins.rb +0 -34
- data/lib/nuggets/ansicolor2css.rb +0 -125
- data/lib/nuggets/argv/option.rb +0 -3
- data/lib/nuggets/argv/option_mixin.rb +0 -85
- data/lib/nuggets/array/boost.rb +0 -5
- data/lib/nuggets/array/boost_mixin.rb +0 -78
- data/lib/nuggets/array/combination.rb +0 -63
- data/lib/nuggets/array/correlation.rb +0 -5
- data/lib/nuggets/array/correlation_mixin.rb +0 -64
- data/lib/nuggets/array/flatten_once.rb +0 -57
- data/lib/nuggets/array/flush.rb +0 -5
- data/lib/nuggets/array/flush_mixin.rb +0 -47
- data/lib/nuggets/array/format.rb +0 -66
- data/lib/nuggets/array/hashify.rb +0 -5
- data/lib/nuggets/array/hashify_mixin.rb +0 -48
- data/lib/nuggets/array/histogram.rb +0 -5
- data/lib/nuggets/array/histogram_mixin.rb +0 -170
- data/lib/nuggets/array/in_order.rb +0 -51
- data/lib/nuggets/array/limit.rb +0 -5
- data/lib/nuggets/array/limit_mixin.rb +0 -57
- data/lib/nuggets/array/mean.rb +0 -5
- data/lib/nuggets/array/mean_mixin.rb +0 -203
- data/lib/nuggets/array/median.rb +0 -5
- data/lib/nuggets/array/median_mixin.rb +0 -74
- data/lib/nuggets/array/mode.rb +0 -5
- data/lib/nuggets/array/mode_mixin.rb +0 -70
- data/lib/nuggets/array/monotone.rb +0 -84
- data/lib/nuggets/array/only.rb +0 -42
- data/lib/nuggets/array/rand.rb +0 -45
- data/lib/nuggets/array/regression.rb +0 -5
- data/lib/nuggets/array/regression_mixin.rb +0 -150
- data/lib/nuggets/array/runiq.rb +0 -5
- data/lib/nuggets/array/runiq_mixin.rb +0 -53
- data/lib/nuggets/array/shuffle.rb +0 -133
- data/lib/nuggets/array/standard_deviation.rb +0 -5
- data/lib/nuggets/array/standard_deviation_mixin.rb +0 -51
- data/lib/nuggets/array/to_hash.rb +0 -65
- data/lib/nuggets/array/variance.rb +0 -5
- data/lib/nuggets/array/variance_mixin.rb +0 -82
- data/lib/nuggets/cli.rb +0 -8
- data/lib/nuggets/content_type.rb +0 -98
- data/lib/nuggets/dotted_decimal.rb +0 -60
- data/lib/nuggets/enumerable/agrep.rb +0 -80
- data/lib/nuggets/enumerable/all_any_extended.rb +0 -67
- data/lib/nuggets/enumerable/minmax.rb +0 -103
- data/lib/nuggets/env/set.rb +0 -3
- data/lib/nuggets/env/set_mixin.rb +0 -68
- data/lib/nuggets/env/user_encoding.rb +0 -3
- data/lib/nuggets/env/user_encoding_mixin.rb +0 -55
- data/lib/nuggets/env/user_home.rb +0 -3
- data/lib/nuggets/env/user_home_mixin.rb +0 -57
- data/lib/nuggets/file/ext.rb +0 -5
- data/lib/nuggets/file/ext_mixin.rb +0 -88
- data/lib/nuggets/file/replace.rb +0 -5
- data/lib/nuggets/file/replace_mixin.rb +0 -56
- data/lib/nuggets/file/sub.rb +0 -5
- data/lib/nuggets/file/sub_mixin.rb +0 -96
- data/lib/nuggets/file/which.rb +0 -5
- data/lib/nuggets/file/which_mixin.rb +0 -73
- data/lib/nuggets/hash/at.rb +0 -69
- data/lib/nuggets/hash/deep_fetch.rb +0 -5
- data/lib/nuggets/hash/deep_fetch_mixin.rb +0 -75
- data/lib/nuggets/hash/deep_merge.rb +0 -5
- data/lib/nuggets/hash/deep_merge_mixin.rb +0 -54
- data/lib/nuggets/hash/idmap.rb +0 -5
- data/lib/nuggets/hash/idmap_mixin.rb +0 -42
- data/lib/nuggets/hash/in_order.rb +0 -44
- data/lib/nuggets/hash/insert.rb +0 -54
- data/lib/nuggets/hash/nest.rb +0 -5
- data/lib/nuggets/hash/nest_mixin.rb +0 -79
- data/lib/nuggets/hash/only.rb +0 -53
- data/lib/nuggets/hash/seen.rb +0 -5
- data/lib/nuggets/hash/seen_mixin.rb +0 -59
- data/lib/nuggets/hash/unroll.rb +0 -5
- data/lib/nuggets/hash/unroll_mixin.rb +0 -89
- data/lib/nuggets/hash/zip.rb +0 -5
- data/lib/nuggets/hash/zip_mixin.rb +0 -160
- data/lib/nuggets/i18n.rb +0 -156
- data/lib/nuggets/integer/factorial.rb +0 -57
- data/lib/nuggets/integer/length.rb +0 -5
- data/lib/nuggets/integer/length_mixin.rb +0 -50
- data/lib/nuggets/integer/map.rb +0 -5
- data/lib/nuggets/integer/map_mixin.rb +0 -43
- data/lib/nuggets/integer/to_binary_s.rb +0 -39
- data/lib/nuggets/io/agrep.rb +0 -44
- data/lib/nuggets/io/interact.rb +0 -5
- data/lib/nuggets/io/interact_mixin.rb +0 -160
- data/lib/nuggets/io/modes.rb +0 -122
- data/lib/nuggets/io/null.rb +0 -5
- data/lib/nuggets/io/null_mixin.rb +0 -41
- data/lib/nuggets/io/redirect.rb +0 -5
- data/lib/nuggets/io/redirect_mixin.rb +0 -51
- data/lib/nuggets/lazy_attr.rb +0 -45
- data/lib/nuggets/log_parser.rb +0 -71
- data/lib/nuggets/log_parser/apache.rb +0 -102
- data/lib/nuggets/log_parser/rails.rb +0 -220
- data/lib/nuggets/lsi.rb +0 -8
- data/lib/nuggets/midos.rb +0 -8
- data/lib/nuggets/mysql.rb +0 -8
- data/lib/nuggets/net/success.rb +0 -60
- data/lib/nuggets/numeric/between.rb +0 -2
- data/lib/nuggets/numeric/duration.rb +0 -101
- data/lib/nuggets/numeric/limit.rb +0 -63
- data/lib/nuggets/numeric/signum.rb +0 -53
- data/lib/nuggets/numeric/to_multiple.rb +0 -62
- data/lib/nuggets/object/blank.rb +0 -20
- data/lib/nuggets/object/blank_mixin.rb +0 -100
- data/lib/nuggets/object/boolean.rb +0 -5
- data/lib/nuggets/object/boolean_mixin.rb +0 -62
- data/lib/nuggets/object/eigenclass.rb +0 -2
- data/lib/nuggets/object/ghost_class.rb +0 -2
- data/lib/nuggets/object/metaclass.rb +0 -2
- data/lib/nuggets/object/msend.rb +0 -5
- data/lib/nuggets/object/msend_mixin.rb +0 -44
- data/lib/nuggets/object/silence.rb +0 -5
- data/lib/nuggets/object/silence_mixin.rb +0 -45
- data/lib/nuggets/object/singleton_class.rb +0 -5
- data/lib/nuggets/object/singleton_class_mixin.rb +0 -96
- data/lib/nuggets/object/uniclass.rb +0 -2
- data/lib/nuggets/object/virtual_class.rb +0 -2
- data/lib/nuggets/pluggable.rb +0 -92
- data/lib/nuggets/proc/bind.rb +0 -5
- data/lib/nuggets/proc/bind_mixin.rb +0 -52
- data/lib/nuggets/range/quantile.rb +0 -5
- data/lib/nuggets/range/quantile_mixin.rb +0 -43
- data/lib/nuggets/rdf/compression.rb +0 -6
- data/lib/nuggets/rdf/prefix.rb +0 -6
- data/lib/nuggets/rdf/turtle.rb +0 -8
- data/lib/nuggets/rdf/turtle/reader.rb +0 -6
- data/lib/nuggets/rdf/uri.rb +0 -6
- data/lib/nuggets/ruby.rb +0 -236
- data/lib/nuggets/statistics.rb +0 -12
- data/lib/nuggets/statistics_mixins.rb +0 -12
- data/lib/nuggets/string/camelscore.rb +0 -5
- data/lib/nuggets/string/camelscore_mixin.rb +0 -117
- data/lib/nuggets/string/capitalize_first.rb +0 -47
- data/lib/nuggets/string/case.rb +0 -82
- data/lib/nuggets/string/evaluate.rb +0 -5
- data/lib/nuggets/string/evaluate_mixin.rb +0 -48
- data/lib/nuggets/string/msub.rb +0 -85
- data/lib/nuggets/string/nsub.rb +0 -66
- data/lib/nuggets/string/sub_with_md.rb +0 -112
- data/lib/nuggets/string/wc.rb +0 -5
- data/lib/nuggets/string/wc_mixin.rb +0 -96
- data/lib/nuggets/string/word_wrap.rb +0 -77
- data/lib/nuggets/string/xor.rb +0 -5
- data/lib/nuggets/string/xor_mixin.rb +0 -60
- data/lib/nuggets/tempfile/open.rb +0 -58
- data/lib/nuggets/uri/content_type.rb +0 -5
- data/lib/nuggets/uri/content_type_mixin.rb +0 -48
- data/lib/nuggets/uri/exist.rb +0 -5
- data/lib/nuggets/uri/exist_mixin.rb +0 -57
- data/lib/nuggets/uri/redirect.rb +0 -5
- data/lib/nuggets/uri/redirect_mixin.rb +0 -102
- data/lib/nuggets/util/ansicolor2css.rb +0 -4
- data/lib/nuggets/util/cli.rb +0 -4
- data/lib/nuggets/util/content_type.rb +0 -4
- data/lib/nuggets/util/dotted_decimal.rb +0 -3
- data/lib/nuggets/util/i18n.rb +0 -4
- data/lib/nuggets/util/lazy_attr.rb +0 -4
- data/lib/nuggets/util/log_parser.rb +0 -4
- data/lib/nuggets/util/log_parser/apache.rb +0 -4
- data/lib/nuggets/util/log_parser/rails.rb +0 -4
- data/lib/nuggets/util/midos.rb +0 -4
- data/lib/nuggets/util/mysql.rb +0 -4
- data/lib/nuggets/util/pluggable.rb +0 -4
- data/lib/nuggets/util/ruby.rb +0 -4
- data/lib/nuggets/version.rb +0 -27
- data/spec/nuggets/array/boost_spec.rb +0 -50
- data/spec/nuggets/array/combination_spec.rb +0 -25
- data/spec/nuggets/array/correlation_spec.rb +0 -81
- data/spec/nuggets/array/flatten_once_spec.rb +0 -16
- data/spec/nuggets/array/flush_spec.rb +0 -43
- data/spec/nuggets/array/format_spec.rb +0 -52
- data/spec/nuggets/array/hashify_spec.rb +0 -41
- data/spec/nuggets/array/histogram_spec.rb +0 -87
- data/spec/nuggets/array/in_order_spec.rb +0 -13
- data/spec/nuggets/array/limit_spec.rb +0 -62
- data/spec/nuggets/array/mean_spec.rb +0 -203
- data/spec/nuggets/array/median_spec.rb +0 -77
- data/spec/nuggets/array/mode_spec.rb +0 -57
- data/spec/nuggets/array/monotone_spec.rb +0 -30
- data/spec/nuggets/array/only_spec.rb +0 -26
- data/spec/nuggets/array/regression_spec.rb +0 -54
- data/spec/nuggets/array/runiq_spec.rb +0 -25
- data/spec/nuggets/array/standard_deviation_spec.rb +0 -33
- data/spec/nuggets/array/to_hash_spec.rb +0 -28
- data/spec/nuggets/array/variance_spec.rb +0 -106
- data/spec/nuggets/dotted_decimal_spec.rb +0 -27
- data/spec/nuggets/enumerable/all_any_extended_spec.rb +0 -31
- data/spec/nuggets/enumerable/minmax_spec.rb +0 -21
- data/spec/nuggets/env/set_spec.rb +0 -29
- data/spec/nuggets/env/user_encoding_spec.rb +0 -38
- data/spec/nuggets/env/user_home_spec.rb +0 -42
- data/spec/nuggets/file/ext_spec.rb +0 -38
- data/spec/nuggets/file/replace_spec.rb +0 -95
- data/spec/nuggets/file/sub_spec.rb +0 -149
- data/spec/nuggets/file/which_spec.rb +0 -22
- data/spec/nuggets/hash/at_spec.rb +0 -19
- data/spec/nuggets/hash/deep_fetch_spec.rb +0 -159
- data/spec/nuggets/hash/deep_merge_spec.rb +0 -78
- data/spec/nuggets/hash/in_order_spec.rb +0 -12
- data/spec/nuggets/hash/insert_spec.rb +0 -13
- data/spec/nuggets/hash/nest_spec.rb +0 -102
- data/spec/nuggets/hash/only_spec.rb +0 -29
- data/spec/nuggets/hash/seen_spec.rb +0 -36
- data/spec/nuggets/hash/unroll_spec.rb +0 -68
- data/spec/nuggets/i18n_spec.rb +0 -13
- data/spec/nuggets/integer/factorial_spec.rb +0 -10
- data/spec/nuggets/integer/length_spec.rb +0 -18
- data/spec/nuggets/integer/map_spec.rb +0 -19
- data/spec/nuggets/integer/to_binary_s_spec.rb +0 -19
- data/spec/nuggets/numeric/duration_spec.rb +0 -25
- data/spec/nuggets/numeric/limit_spec.rb +0 -16
- data/spec/nuggets/numeric/signum_spec.rb +0 -16
- data/spec/nuggets/numeric/to_multiple_spec.rb +0 -16
- data/spec/nuggets/object/blank_spec.rb +0 -34
- data/spec/nuggets/object/boolean_spec.rb +0 -23
- data/spec/nuggets/object/msend_spec.rb +0 -25
- data/spec/nuggets/object/silence_spec.rb +0 -36
- data/spec/nuggets/object/singleton_class_spec.rb +0 -51
- data/spec/nuggets/proc/bind_spec.rb +0 -28
- data/spec/nuggets/range/quantile_spec.rb +0 -33
- data/spec/nuggets/string/camelscore_spec.rb +0 -114
- data/spec/nuggets/string/capitalize_first_spec.rb +0 -13
- data/spec/nuggets/string/case_spec.rb +0 -31
- data/spec/nuggets/string/evaluate_spec.rb +0 -24
- data/spec/nuggets/string/msub_spec.rb +0 -20
- data/spec/nuggets/string/nsub_spec.rb +0 -13
- data/spec/nuggets/string/sub_with_md_spec.rb +0 -25
- data/spec/nuggets/string/wc_spec.rb +0 -73
- data/spec/nuggets/string/word_wrap_spec.rb +0 -81
- data/spec/nuggets/string/xor_spec.rb +0 -57
- data/spec/nuggets/uri/content_type_spec.rb +0 -42
- data/spec/nuggets/uri/exist_spec.rb +0 -49
- data/spec/spec_helper.rb +0 -36
data/lib/nuggets/io/null.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
###############################################################################
|
3
|
-
# #
|
4
|
-
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
5
|
-
# language. #
|
6
|
-
# #
|
7
|
-
# Copyright (C) 2007-2011 Jens Wille #
|
8
|
-
# #
|
9
|
-
# Authors: #
|
10
|
-
# Jens Wille <jens.wille@gmail.com> #
|
11
|
-
# #
|
12
|
-
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
13
|
-
# under the terms of the GNU Affero General Public License as published by #
|
14
|
-
# the Free Software Foundation; either version 3 of the License, or (at your #
|
15
|
-
# option) any later version. #
|
16
|
-
# #
|
17
|
-
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
18
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
19
|
-
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License #
|
20
|
-
# for more details. #
|
21
|
-
# #
|
22
|
-
# You should have received a copy of the GNU Affero General Public License #
|
23
|
-
# along with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
24
|
-
# #
|
25
|
-
###############################################################################
|
26
|
-
#++
|
27
|
-
|
28
|
-
module Nuggets
|
29
|
-
class IO
|
30
|
-
module NullMixin
|
31
|
-
|
32
|
-
NULL = case ::RUBY_PLATFORM
|
33
|
-
when /mswin|mingw/i then 'NUL'
|
34
|
-
when /openvms/i then 'NL:'
|
35
|
-
when /amiga/i then 'NIL:'
|
36
|
-
else '/dev/null'
|
37
|
-
end.freeze
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
data/lib/nuggets/io/redirect.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
###############################################################################
|
3
|
-
# #
|
4
|
-
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
5
|
-
# language. #
|
6
|
-
# #
|
7
|
-
# Copyright (C) 2007-2012 Jens Wille #
|
8
|
-
# #
|
9
|
-
# Authors: #
|
10
|
-
# Jens Wille <jens.wille@gmail.com> #
|
11
|
-
# #
|
12
|
-
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
13
|
-
# under the terms of the GNU Affero General Public License as published by #
|
14
|
-
# the Free Software Foundation; either version 3 of the License, or (at your #
|
15
|
-
# option) any later version. #
|
16
|
-
# #
|
17
|
-
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
18
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
19
|
-
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License #
|
20
|
-
# for more details. #
|
21
|
-
# #
|
22
|
-
# You should have received a copy of the GNU Affero General Public License #
|
23
|
-
# along with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
24
|
-
# #
|
25
|
-
###############################################################################
|
26
|
-
#++
|
27
|
-
|
28
|
-
require 'nuggets/io/null_mixin'
|
29
|
-
|
30
|
-
module Nuggets
|
31
|
-
class IO
|
32
|
-
module RedirectMixin
|
33
|
-
|
34
|
-
def redirect(target = NullMixin::NULL, mode = 'w')
|
35
|
-
unless target.is_a?(self.class)
|
36
|
-
target = ::File.open(target, mode)
|
37
|
-
close_target = true
|
38
|
-
end
|
39
|
-
|
40
|
-
prev = dup
|
41
|
-
reopen(target)
|
42
|
-
|
43
|
-
yield
|
44
|
-
ensure
|
45
|
-
reopen(prev) if prev
|
46
|
-
target.close if close_target
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
data/lib/nuggets/lazy_attr.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
###############################################################################
|
3
|
-
# #
|
4
|
-
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
5
|
-
# language. #
|
6
|
-
# #
|
7
|
-
# Copyright (C) 2007-2012 Jens Wille #
|
8
|
-
# #
|
9
|
-
# Authors: #
|
10
|
-
# Jens Wille <jens.wille@gmail.com> #
|
11
|
-
# #
|
12
|
-
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
13
|
-
# under the terms of the GNU Affero General Public License as published by #
|
14
|
-
# the Free Software Foundation; either version 3 of the License, or (at your #
|
15
|
-
# option) any later version. #
|
16
|
-
# #
|
17
|
-
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
18
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
19
|
-
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License #
|
20
|
-
# for more details. #
|
21
|
-
# #
|
22
|
-
# You should have received a copy of the GNU Affero General Public License #
|
23
|
-
# along with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
24
|
-
# #
|
25
|
-
###############################################################################
|
26
|
-
#++
|
27
|
-
|
28
|
-
module Nuggets
|
29
|
-
|
30
|
-
module LazyAttr
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def lazy_attr(attr, freeze = true)
|
35
|
-
class << self; self; end.class_eval { attr_reader attr }
|
36
|
-
|
37
|
-
value = instance_variable_get(name = "@#{attr}") ||
|
38
|
-
instance_variable_set(name, yield)
|
39
|
-
|
40
|
-
freeze ? value.freeze : value
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
data/lib/nuggets/log_parser.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
###############################################################################
|
3
|
-
# #
|
4
|
-
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
5
|
-
# language. #
|
6
|
-
# #
|
7
|
-
# Copyright (C) 2007-2012 Jens Wille #
|
8
|
-
# #
|
9
|
-
# Authors: #
|
10
|
-
# Jens Wille <jens.wille@gmail.com> #
|
11
|
-
# #
|
12
|
-
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
13
|
-
# under the terms of the GNU Affero General Public License as published by #
|
14
|
-
# the Free Software Foundation; either version 3 of the License, or (at your #
|
15
|
-
# option) any later version. #
|
16
|
-
# #
|
17
|
-
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
18
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
19
|
-
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License #
|
20
|
-
# for more details. #
|
21
|
-
# #
|
22
|
-
# You should have received a copy of the GNU Affero General Public License #
|
23
|
-
# along with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
24
|
-
# #
|
25
|
-
###############################################################################
|
26
|
-
#++
|
27
|
-
|
28
|
-
require 'zlib'
|
29
|
-
|
30
|
-
module Nuggets
|
31
|
-
module LogParser
|
32
|
-
|
33
|
-
extend self
|
34
|
-
|
35
|
-
GZ_EXT_RE = %r{\.gz\z}
|
36
|
-
|
37
|
-
def self.register(base, *modules)
|
38
|
-
base.send(:include, *modules << self)
|
39
|
-
base.extend(base)
|
40
|
-
end
|
41
|
-
|
42
|
-
def parse(input)
|
43
|
-
entry = {}
|
44
|
-
|
45
|
-
input.each { |line| parse_line(line, entry) {
|
46
|
-
unless entry.empty?
|
47
|
-
yield entry.dup
|
48
|
-
entry.clear
|
49
|
-
end
|
50
|
-
} }
|
51
|
-
|
52
|
-
yield entry unless entry.empty?
|
53
|
-
end
|
54
|
-
|
55
|
-
def parse_line(line, entry = {})
|
56
|
-
# Yield when entry complete. Preferrably return +entry+.
|
57
|
-
raise NotImplementedError, 'must be implemented by type'
|
58
|
-
end
|
59
|
-
|
60
|
-
def parse_file(file, &block)
|
61
|
-
block ||= (entries = []; lambda { |entry| entries << entry })
|
62
|
-
|
63
|
-
(file =~ GZ_EXT_RE ? Zlib::GzipReader : ::File).open(file) { |f|
|
64
|
-
block.arity == 1 ? parse(f, &block) : block[f, method(:parse)]
|
65
|
-
}
|
66
|
-
|
67
|
-
entries
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
|
-
end
|
@@ -1,102 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
###############################################################################
|
3
|
-
# #
|
4
|
-
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
5
|
-
# language. #
|
6
|
-
# #
|
7
|
-
# Copyright (C) 2007-2012 Jens Wille #
|
8
|
-
# #
|
9
|
-
# Authors: #
|
10
|
-
# Jens Wille <jens.wille@gmail.com> #
|
11
|
-
# #
|
12
|
-
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
13
|
-
# under the terms of the GNU Affero General Public License as published by #
|
14
|
-
# the Free Software Foundation; either version 3 of the License, or (at your #
|
15
|
-
# option) any later version. #
|
16
|
-
# #
|
17
|
-
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
18
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
19
|
-
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License #
|
20
|
-
# for more details. #
|
21
|
-
# #
|
22
|
-
# You should have received a copy of the GNU Affero General Public License #
|
23
|
-
# along with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
24
|
-
# #
|
25
|
-
###############################################################################
|
26
|
-
#++
|
27
|
-
|
28
|
-
require 'nuggets/log_parser'
|
29
|
-
|
30
|
-
module Nuggets
|
31
|
-
module LogParser
|
32
|
-
module Apache
|
33
|
-
|
34
|
-
extend self
|
35
|
-
|
36
|
-
DEFAULT_RE = %r{(.*?)}
|
37
|
-
|
38
|
-
DIRECTIVES = {
|
39
|
-
'h' => [:ip, %r{(\d+(?:\.\d+){3}|[\w.-]+)}],
|
40
|
-
'l' => [:auth, DEFAULT_RE],
|
41
|
-
'u' => [:username, DEFAULT_RE],
|
42
|
-
't' => [:datetime, %r{\[(.*?)\]}],
|
43
|
-
'r' => [:request, DEFAULT_RE],
|
44
|
-
'R' => [:request, %r{(.*?)(?:"|\z)}],
|
45
|
-
's' => [:status, %r{(\d+)}],
|
46
|
-
'b' => [:bytecount, %r{(-|\d+)}],
|
47
|
-
'v' => [:domain, DEFAULT_RE],
|
48
|
-
'i' => [nil, DEFAULT_RE],
|
49
|
-
}
|
50
|
-
|
51
|
-
DIRECTIVES_RE = %r{%.*?(?:\{(.*?)\})?([#{DIRECTIVES.keys.join}])([\s\\"]*)}
|
52
|
-
|
53
|
-
ORDER = []
|
54
|
-
|
55
|
-
class << self
|
56
|
-
|
57
|
-
def register(name, format)
|
58
|
-
base = const_set(name, Module.new)
|
59
|
-
|
60
|
-
re, items = parse_format(format)
|
61
|
-
base.const_set(:RE, re)
|
62
|
-
base.const_set(:ITEMS, items)
|
63
|
-
|
64
|
-
ORDER << base
|
65
|
-
LogParser.register(base, self)
|
66
|
-
end
|
67
|
-
|
68
|
-
def parse_format(format)
|
69
|
-
re, items = '\A', []
|
70
|
-
|
71
|
-
format.scan(DIRECTIVES_RE) { |h, c, e|
|
72
|
-
i, r = DIRECTIVES[c]
|
73
|
-
re << r.source << e.gsub(/\s/, '\\s')
|
74
|
-
items << i ||= h.downcase.tr('-', '_').to_sym
|
75
|
-
}
|
76
|
-
|
77
|
-
[Regexp.new(re), items]
|
78
|
-
end
|
79
|
-
|
80
|
-
def detect_type(line)
|
81
|
-
ORDER.find { |type| line =~ type::RE }
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
[ [:Combined, '%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"'],
|
87
|
-
[:Common, '%h %l %u %t "%r" %>s %b'],
|
88
|
-
[:Minimal, '%h %l %u %t "%R']
|
89
|
-
].each { |name, format| register(name, format) }
|
90
|
-
|
91
|
-
def parse_line(line, entry = {})
|
92
|
-
if md = self::RE.match(line)
|
93
|
-
self::ITEMS.each_with_index { |k, i| entry[k] = md[i + 1] }
|
94
|
-
yield if block_given?
|
95
|
-
end
|
96
|
-
|
97
|
-
entry
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
@@ -1,220 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
###############################################################################
|
3
|
-
# #
|
4
|
-
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
5
|
-
# language. #
|
6
|
-
# #
|
7
|
-
# Copyright (C) 2007-2012 Jens Wille #
|
8
|
-
# #
|
9
|
-
# Authors: #
|
10
|
-
# Jens Wille <jens.wille@gmail.com> #
|
11
|
-
# #
|
12
|
-
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
13
|
-
# under the terms of the GNU Affero General Public License as published by #
|
14
|
-
# the Free Software Foundation; either version 3 of the License, or (at your #
|
15
|
-
# option) any later version. #
|
16
|
-
# #
|
17
|
-
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
18
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
19
|
-
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License #
|
20
|
-
# for more details. #
|
21
|
-
# #
|
22
|
-
# You should have received a copy of the GNU Affero General Public License #
|
23
|
-
# along with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
24
|
-
# #
|
25
|
-
###############################################################################
|
26
|
-
#++
|
27
|
-
|
28
|
-
require 'nuggets/log_parser'
|
29
|
-
|
30
|
-
module Nuggets
|
31
|
-
module LogParser
|
32
|
-
module Rails
|
33
|
-
|
34
|
-
LogParser.register(self)
|
35
|
-
|
36
|
-
# Log line prefix
|
37
|
-
PREFIX_RE = %r{
|
38
|
-
\A
|
39
|
-
(?:
|
40
|
-
\[
|
41
|
-
(\d+) # pid
|
42
|
-
:
|
43
|
-
(.*?) # host
|
44
|
-
\]
|
45
|
-
\s
|
46
|
-
)?
|
47
|
-
\s*
|
48
|
-
}x
|
49
|
-
|
50
|
-
# Log entry separator
|
51
|
-
SEPARATOR_RE = %r{
|
52
|
-
\s+\|\s+
|
53
|
-
}x
|
54
|
-
|
55
|
-
# Log line patterns
|
56
|
-
ITEMS = [
|
57
|
-
[:processing, {
|
58
|
-
:re => %r{
|
59
|
-
#{PREFIX_RE} # pid, host
|
60
|
-
Processing\s+
|
61
|
-
(\w+) # controller
|
62
|
-
\#
|
63
|
-
(\w+) # action
|
64
|
-
\s+
|
65
|
-
\(
|
66
|
-
for\s+
|
67
|
-
(.*?) # ip
|
68
|
-
\s+at\s+
|
69
|
-
(.*?) # datetime
|
70
|
-
\)
|
71
|
-
\s+
|
72
|
-
\[
|
73
|
-
(\w+) # request_method
|
74
|
-
\]
|
75
|
-
}xo,
|
76
|
-
:keys => [:controller, :action, :ip, :datetime, :request_method]
|
77
|
-
}],
|
78
|
-
[:session_id, {
|
79
|
-
:re => %r{
|
80
|
-
#{PREFIX_RE} # pid, host
|
81
|
-
Session\sID:\s+
|
82
|
-
(\S+) # sid
|
83
|
-
}xo,
|
84
|
-
:keys => [:sid]
|
85
|
-
}],
|
86
|
-
[:parameters, {
|
87
|
-
:re => %r{
|
88
|
-
#{PREFIX_RE} # pid, host
|
89
|
-
Parameters:\s+
|
90
|
-
(\{.*\}) # params
|
91
|
-
}xo, #}
|
92
|
-
:proc => lambda { |entry, md|
|
93
|
-
entry[:params_hash] = md[3].hash
|
94
|
-
entry[:params] = begin
|
95
|
-
eval("$SAFE = 3\n#{md[3].gsub(/#<.*?>/, '%q{\&}')}", nil, __FILE__, __LINE__) # !!!
|
96
|
-
rescue SyntaxError, SecurityError
|
97
|
-
{}
|
98
|
-
end
|
99
|
-
}
|
100
|
-
}],
|
101
|
-
[:client_info, {
|
102
|
-
:re => %r{
|
103
|
-
#{PREFIX_RE} # pid, host
|
104
|
-
Client\sinfo:\s+
|
105
|
-
UA\s+=\s+
|
106
|
-
(.*?) # user_agent
|
107
|
-
#{SEPARATOR_RE}
|
108
|
-
LANG\s+=\s+
|
109
|
-
(.*) # accept_language
|
110
|
-
}xo,
|
111
|
-
:keys => [:user_agent, :accept_language]
|
112
|
-
}],
|
113
|
-
[:referer, {
|
114
|
-
:re => %r{
|
115
|
-
#{PREFIX_RE} # pid, host
|
116
|
-
Referer:\s+
|
117
|
-
(.*) # referer
|
118
|
-
}xo,
|
119
|
-
:keys => [:referer]
|
120
|
-
}],
|
121
|
-
[:meta, {
|
122
|
-
:re => %r{
|
123
|
-
#{PREFIX_RE} # pid, host
|
124
|
-
Meta:\s+
|
125
|
-
User\s+=\s+
|
126
|
-
(.*?) # user_id
|
127
|
-
#{SEPARATOR_RE}
|
128
|
-
Institution\s+=\s+
|
129
|
-
(.*) # institution_id
|
130
|
-
}xo,
|
131
|
-
:keys => [:user_id, :institution_id]
|
132
|
-
}],
|
133
|
-
[:stats, {
|
134
|
-
:re => %r{
|
135
|
-
#{PREFIX_RE} # pid, host
|
136
|
-
Stats:\s+
|
137
|
-
(.*) # flags
|
138
|
-
}xo,
|
139
|
-
:proc => lambda { |entry, md|
|
140
|
-
entry[:flags] = md[3].split(SEPARATOR_RE)
|
141
|
-
}
|
142
|
-
}],
|
143
|
-
[:oauth, {
|
144
|
-
:re => %r{
|
145
|
-
#{PREFIX_RE} # pid, host
|
146
|
-
OAuth:\s+
|
147
|
-
Token\s+=\s+
|
148
|
-
(.*?)#(.*?) # token_type, token
|
149
|
-
#{SEPARATOR_RE}
|
150
|
-
User\s+=\s+
|
151
|
-
(.*?) # user_id
|
152
|
-
#{SEPARATOR_RE}
|
153
|
-
Client\s+=\s+
|
154
|
-
(.*) # client_id
|
155
|
-
}xo,
|
156
|
-
:keys => [:token_type, :token, :user_id, :client_id]
|
157
|
-
}],
|
158
|
-
[:benchmark, {
|
159
|
-
:re => %r{
|
160
|
-
#{PREFIX_RE} # pid, host
|
161
|
-
Completed\sin\s+
|
162
|
-
(\S+) # runtime
|
163
|
-
.*?
|
164
|
-
(?: #- OPTIONAL
|
165
|
-
#{SEPARATOR_RE}
|
166
|
-
Rendering:\s+
|
167
|
-
(\S+) # rendering_runtime
|
168
|
-
.*?
|
169
|
-
)?
|
170
|
-
(?: #- OPTIONAL
|
171
|
-
#{SEPARATOR_RE}
|
172
|
-
DB:\s+
|
173
|
-
(\S+) # db_runtime
|
174
|
-
.*?
|
175
|
-
)?
|
176
|
-
(?: #- OPTIONAL
|
177
|
-
#{SEPARATOR_RE}
|
178
|
-
Mem:\s+
|
179
|
-
\S+
|
180
|
-
.*?
|
181
|
-
)?
|
182
|
-
#{SEPARATOR_RE}
|
183
|
-
(.*?) # status
|
184
|
-
\s+
|
185
|
-
\[
|
186
|
-
(.*) # request_uri
|
187
|
-
\]
|
188
|
-
}xo,
|
189
|
-
:keys => [:runtime, :rendering_runtime, :db_runtime, :status, :request_uri]
|
190
|
-
}]
|
191
|
-
]
|
192
|
-
|
193
|
-
ITEMS.each { |_, item|
|
194
|
-
item[:proc] ||= lambda { |entry, md|
|
195
|
-
item[:keys].each_with_index { |k, i|
|
196
|
-
entry[k] = md[i + 3] # 1 = pid, 2 = host
|
197
|
-
}
|
198
|
-
}
|
199
|
-
}
|
200
|
-
|
201
|
-
def parse_line(line, entry = {})
|
202
|
-
ITEMS.each { |key, item|
|
203
|
-
if md = item[:re].match(line)
|
204
|
-
if key == :processing
|
205
|
-
yield if block_given?
|
206
|
-
entry[:pid], entry[:host] = md[1], md[2]
|
207
|
-
end
|
208
|
-
|
209
|
-
item[:proc][entry, md]
|
210
|
-
|
211
|
-
break
|
212
|
-
end
|
213
|
-
}
|
214
|
-
|
215
|
-
entry
|
216
|
-
end
|
217
|
-
|
218
|
-
end
|
219
|
-
end
|
220
|
-
end
|