rmtools 1.2.14 → 1.3.0
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/LICENSE +16 -0
- data/Manifest.txt +80 -76
- data/README.md +137 -0
- data/Rakefile +7 -8
- data/lib/rmtools/core/class.rb +13 -7
- data/lib/rmtools/core/kernel.rb +4 -0
- data/lib/rmtools/core/object.rb +25 -0
- data/lib/rmtools/db/active_record.rb +28 -3
- data/lib/rmtools/dev/observing.rb +1 -0
- data/lib/rmtools/dev/trace_format.rb +4 -4
- data/lib/rmtools/enumerable/common.rb +5 -1
- data/lib/rmtools/enumerable/hash.rb +6 -0
- data/lib/rmtools/enumerable/traversal.rb +164 -0
- data/lib/rmtools/fs/dir.rb +9 -2
- data/lib/rmtools/fs/io.rb +19 -14
- data/lib/rmtools/functional/decorate.rb +2 -0
- data/lib/rmtools/lang/ansi.rb +5 -3
- data/lib/rmtools/lang/cyrillic.rb +48 -35
- data/lib/rmtools/text/string_parse.rb +23 -8
- data/lib/rmtools/text/string_simple.rb +28 -0
- data/lib/rmtools.so +0 -0
- metadata +89 -85
data/LICENSE
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Copyright (c) 2010-2013
|
|
2
|
+
Sergey Baev <tinbka@gmail.com>
|
|
3
|
+
|
|
4
|
+
This work is licensed under the same license as Ruby language.
|
|
5
|
+
|
|
6
|
+
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
7
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
8
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
9
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
10
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
11
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
12
|
+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
13
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
14
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
15
|
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
16
|
+
SUCH DAMAGE.
|
data/Manifest.txt
CHANGED
|
@@ -1,97 +1,101 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
lib/rmtools.
|
|
5
|
-
lib/rmtools/
|
|
6
|
-
lib/rmtools/
|
|
7
|
-
lib/rmtools/
|
|
1
|
+
License.txt
|
|
2
|
+
README.txt
|
|
3
|
+
lib/rmtools_dev.rb
|
|
4
|
+
lib/rmtools.so
|
|
5
|
+
lib/rmtools/core/module.rb
|
|
6
|
+
lib/rmtools/core/js.rb
|
|
7
|
+
lib/rmtools/core/string_compliance.rb
|
|
8
|
+
lib/rmtools/core/kernel.rb
|
|
9
|
+
lib/rmtools/core/arguments.rb
|
|
10
|
+
lib/rmtools/core/object.rb
|
|
11
|
+
lib/rmtools/core/deprecation.rb
|
|
12
|
+
lib/rmtools/core/aliases.rb
|
|
13
|
+
lib/rmtools/core/proc.rb
|
|
14
|
+
lib/rmtools/core/class.rb
|
|
15
|
+
lib/rmtools/core/numeric.rb
|
|
16
|
+
lib/rmtools/core/boolean.rb
|
|
17
|
+
lib/rmtools/core/regexp.rb
|
|
18
|
+
lib/rmtools/core/threadify.rb
|
|
19
|
+
lib/rmtools/rand/range.rb
|
|
20
|
+
lib/rmtools/rand/string.rb
|
|
21
|
+
lib/rmtools/rand/array.rb
|
|
22
|
+
lib/rmtools/rand/enum.rb
|
|
23
|
+
lib/rmtools/db.rb
|
|
24
|
+
lib/rmtools/install.rb
|
|
25
|
+
lib/rmtools/conversions.rb
|
|
26
|
+
lib/rmtools/functional.rb
|
|
27
|
+
lib/rmtools/require.rb
|
|
28
|
+
lib/rmtools/lang.rb
|
|
29
|
+
lib/rmtools/time.rb
|
|
30
|
+
lib/rmtools/fs.rb
|
|
8
31
|
lib/rmtools/fs/dir.rb
|
|
32
|
+
lib/rmtools/fs/file.rb
|
|
9
33
|
lib/rmtools/fs/tools.rb
|
|
10
|
-
lib/rmtools/
|
|
11
|
-
lib/rmtools/ip/string.rb
|
|
12
|
-
lib/rmtools/dev/present.rb
|
|
13
|
-
lib/rmtools/dev/blackhole.rb
|
|
14
|
-
lib/rmtools/dev/observing.rb
|
|
34
|
+
lib/rmtools/fs/io.rb
|
|
15
35
|
lib/rmtools/dev/traceback.rb
|
|
16
|
-
lib/rmtools/dev/binding.rb
|
|
17
36
|
lib/rmtools/dev/logging.rb
|
|
18
|
-
lib/rmtools/dev/
|
|
19
|
-
lib/rmtools/dev/highlight.rb
|
|
37
|
+
lib/rmtools/dev/binding.rb
|
|
20
38
|
lib/rmtools/dev/timer.rb
|
|
39
|
+
lib/rmtools/dev/blackhole.rb
|
|
21
40
|
lib/rmtools/dev/code_reader.rb
|
|
22
|
-
lib/rmtools/
|
|
41
|
+
lib/rmtools/dev/trace_format.rb
|
|
42
|
+
lib/rmtools/dev/highlight.rb
|
|
43
|
+
lib/rmtools/dev/present.rb
|
|
44
|
+
lib/rmtools/dev/observing.rb
|
|
45
|
+
lib/rmtools/b.rb
|
|
46
|
+
lib/rmtools/init.rb
|
|
47
|
+
lib/rmtools/text.rb
|
|
23
48
|
lib/rmtools/xml/string.rb
|
|
24
|
-
lib/rmtools/xml/libxml.rb
|
|
25
|
-
lib/rmtools/xml/finders.rb
|
|
26
49
|
lib/rmtools/xml/node.rb
|
|
50
|
+
lib/rmtools/xml/xpath.rb
|
|
27
51
|
lib/rmtools/xml/document.rb
|
|
28
|
-
lib/rmtools/
|
|
29
|
-
lib/rmtools/
|
|
30
|
-
lib/rmtools/
|
|
31
|
-
lib/rmtools/
|
|
32
|
-
lib/rmtools/
|
|
33
|
-
lib/rmtools/
|
|
34
|
-
lib/rmtools/core
|
|
35
|
-
lib/rmtools/
|
|
36
|
-
lib/rmtools/core/threadify.rb
|
|
37
|
-
lib/rmtools/core/module.rb
|
|
38
|
-
lib/rmtools/core/object.rb
|
|
39
|
-
lib/rmtools/core/deprecation.rb
|
|
40
|
-
lib/rmtools/core/regexp.rb
|
|
41
|
-
lib/rmtools/core/class.rb
|
|
42
|
-
lib/rmtools/core/proc.rb
|
|
43
|
-
lib/rmtools/lang/ansi.rb
|
|
44
|
-
lib/rmtools/lang/regexp.rb
|
|
45
|
-
lib/rmtools/lang/cyrillic.rb
|
|
46
|
-
lib/rmtools/rand/string.rb
|
|
47
|
-
lib/rmtools/rand/enum.rb
|
|
48
|
-
lib/rmtools/rand/range.rb
|
|
49
|
-
lib/rmtools/rand/array.rb
|
|
52
|
+
lib/rmtools/xml/finders.rb
|
|
53
|
+
lib/rmtools/xml/libxml.rb
|
|
54
|
+
lib/rmtools/ip.rb
|
|
55
|
+
lib/rmtools/dev.rb
|
|
56
|
+
lib/rmtools/rand.rb
|
|
57
|
+
lib/rmtools/db/active_record.rb
|
|
58
|
+
lib/rmtools/core.rb
|
|
59
|
+
lib/rmtools/console.rb
|
|
50
60
|
lib/rmtools/text/string_simple.rb
|
|
61
|
+
lib/rmtools/text/string_split.rb
|
|
51
62
|
lib/rmtools/text/string_scanner.rb
|
|
52
63
|
lib/rmtools/text/textilize.rb
|
|
53
64
|
lib/rmtools/text/string_rtl.rb
|
|
54
|
-
lib/rmtools/text/string_split.rb
|
|
55
|
-
lib/rmtools/text/string_parse.rb
|
|
56
65
|
lib/rmtools/text/regexp.rb
|
|
66
|
+
lib/rmtools/text/string_parse.rb
|
|
67
|
+
lib/rmtools/lang/cyrillic.rb
|
|
68
|
+
lib/rmtools/lang/ansi.rb
|
|
69
|
+
lib/rmtools/lang/regexp.rb
|
|
70
|
+
lib/rmtools/conversions/string.rb
|
|
71
|
+
lib/rmtools/conversions/json.rb
|
|
72
|
+
lib/rmtools/conversions/enum.rb
|
|
73
|
+
lib/rmtools/conversions/int.rb
|
|
57
74
|
lib/rmtools/time/russian.rb
|
|
58
75
|
lib/rmtools/time/global.rb
|
|
59
|
-
lib/rmtools/
|
|
60
|
-
lib/rmtools/
|
|
61
|
-
lib/rmtools/
|
|
62
|
-
lib/rmtools/
|
|
63
|
-
lib/rmtools/
|
|
64
|
-
lib/rmtools/db.rb
|
|
65
|
-
lib/rmtools/fs.rb
|
|
66
|
-
lib/rmtools/ip.rb
|
|
67
|
-
lib/rmtools/lang.rb
|
|
68
|
-
lib/rmtools/functional.rb
|
|
69
|
-
lib/rmtools/install.rb
|
|
70
|
-
lib/rmtools/functional/decorate.rb
|
|
76
|
+
lib/rmtools/enumerable.rb
|
|
77
|
+
lib/rmtools/dev_min.rb
|
|
78
|
+
lib/rmtools/ip/string.rb
|
|
79
|
+
lib/rmtools/ip/numeric.rb
|
|
80
|
+
lib/rmtools/xml.rb
|
|
71
81
|
lib/rmtools/functional/fold.rb
|
|
82
|
+
lib/rmtools/functional/decorate.rb
|
|
72
83
|
lib/rmtools/functional/unfold.rb
|
|
73
|
-
lib/rmtools/text.rb
|
|
74
|
-
lib/rmtools/console.rb
|
|
75
|
-
lib/rmtools/time.rb
|
|
76
|
-
lib/rmtools/dev.rb
|
|
77
|
-
lib/rmtools/enumerable/common.rb
|
|
78
84
|
lib/rmtools/enumerable/range.rb
|
|
79
|
-
lib/rmtools/enumerable/
|
|
80
|
-
lib/rmtools/enumerable/
|
|
85
|
+
lib/rmtools/enumerable/traversal.rb
|
|
86
|
+
lib/rmtools/enumerable/common.rb
|
|
81
87
|
lib/rmtools/enumerable/object_space.rb
|
|
82
88
|
lib/rmtools/enumerable/array_iterators.rb
|
|
83
|
-
lib/rmtools/
|
|
84
|
-
lib/rmtools/
|
|
85
|
-
lib/rmtools/
|
|
86
|
-
lib/rmtools/
|
|
87
|
-
lib/rmtools/
|
|
88
|
-
lib/rmtools
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
./License.txt
|
|
97
|
-
./README.txt
|
|
89
|
+
lib/rmtools/enumerable/array.rb
|
|
90
|
+
lib/rmtools/enumerable/hash.rb
|
|
91
|
+
lib/rmtools/console/coloring.rb
|
|
92
|
+
lib/rmtools/console/printing.rb
|
|
93
|
+
lib/rmtools/console/highlight.rb
|
|
94
|
+
lib/rmtools.rb
|
|
95
|
+
README.md
|
|
96
|
+
Manifest.txt
|
|
97
|
+
ext/rmtools.cpp
|
|
98
|
+
ext/rmtools.h
|
|
99
|
+
ext/extconf.rb
|
|
100
|
+
LICENSE
|
|
101
|
+
Rakefile
|
data/README.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
### RMTools
|
|
2
|
+
[github](https://github.com/tinbka/rmtools)
|
|
3
|
+
|
|
4
|
+
Collection of helpers for any need: strings, enumerables, Module... hundreds of bicycles, shortcuts you ever wanted to implement is here, optimized for performance.
|
|
5
|
+
Small dev library (in progress for ever): fast and smart logger, binding explorer, backtrace formatter, all are console-colored.
|
|
6
|
+
Started from basic classes, now it contains low-level helpers for ActiveRecord and makes LibXML more jQueryish.
|
|
7
|
+
|
|
8
|
+
RMTools is based on opinion that some boiler-plate should be thrown away from Ruby making it more expressive with no (0~10%) performance penalty:
|
|
9
|
+
`hash['id']` -> `hash.id`
|
|
10
|
+
`ary.map(&:id)` -> `ary.ids`
|
|
11
|
+
`ary.map {|h| h['id']}` -> `ary.ids`
|
|
12
|
+
`comments.posts.sorted_uniq_by_id.select_by_user_id(user_id).sum_points` -> `comments.map {|c| c.post}.sort_by {|p| p.id}.uniq_by {|p| p.id}.select {|p| p.user_id == user_id}.sum {|p| p.points}`
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
It's still randomly documented since it's just my working tool.
|
|
17
|
+
|
|
18
|
+
#### Expected to complete:
|
|
19
|
+
|
|
20
|
+
* Ruby code parser (StringScanner-based) reading array of loaded ruby-files and making accurate hash-table of defined methods {"Class#method" => "def ... end"}
|
|
21
|
+
* JSON-formatter for output ruby objects content in HTML form in order to inspect big objects using browser abilities
|
|
22
|
+
* Redis addon (inspired by redis-objects): store and search relations, data-typing. (maybe I'll create another gem for that)
|
|
23
|
+
|
|
24
|
+
### CHANGES
|
|
25
|
+
|
|
26
|
+
##### Version 1.3.0
|
|
27
|
+
|
|
28
|
+
* Added ::ValueTraversal and ::KeyValueTraversal modules for treeish dir/enumerable search
|
|
29
|
+
* String
|
|
30
|
+
* * Cyrillic support: #fupcase, #fdowncase and instant up/down versions
|
|
31
|
+
* * #to_search, #squeeze_newlines, #recordize
|
|
32
|
+
* * key :js_caller to #parse for JS stacktrace lines as it given by stacktrace.js library
|
|
33
|
+
* Added AR::Base::boolean_scopes! and ::non_null_scopes!
|
|
34
|
+
* Added Object#ifndef for ivars caching
|
|
35
|
+
* Fixed bugs
|
|
36
|
+
* * Class#__init__ (case with nested classes)
|
|
37
|
+
* * AR::Base::select_rand (case with :where query)
|
|
38
|
+
* * ::rw and ::write (cases with encoding fail and non-string argument)
|
|
39
|
+
* Described the library and *marked down* this readme
|
|
40
|
+
|
|
41
|
+
##### Version 1.2.14
|
|
42
|
+
|
|
43
|
+
* Smartified Array bicycles: #index_where, #indices_where, #set_where, #set_all_where, #del_where, #del_all_where
|
|
44
|
+
* Added #arrange_by to Array enumerators
|
|
45
|
+
* Added AR::Base::enum for virtual "enum" type support
|
|
46
|
+
* Updated detecting of xml charset encoding for ruby 1.9
|
|
47
|
+
* Fixed bug with empty trace formatting and Array#get_args with non-equalable argument
|
|
48
|
+
|
|
49
|
+
##### Version 1.2.11
|
|
50
|
+
|
|
51
|
+
* Added Array#select_by and #reject_by pattern-iterators
|
|
52
|
+
* Fixed ActiveRecord::Base.select_rand
|
|
53
|
+
* Restricted RMTools.format_trace to use with Rails because of hard slowdown
|
|
54
|
+
* Updated Proc constants for ruby 1.9
|
|
55
|
+
|
|
56
|
+
##### Version 1.2.10
|
|
57
|
+
|
|
58
|
+
* Update String#parse:caller to parse ruby 1.9 "block level". Now block level processes in RMLogger and RMTools.format_trace
|
|
59
|
+
* lib/dev/traceback.rb now applies to ruby > 1.9 as well
|
|
60
|
+
* Support of Yajl or (if not installed) JSON for #to_json and #from_json. Overwrites ActiveSupport's ::encode and ::decode since they're so damn slow.
|
|
61
|
+
|
|
62
|
+
##### Version 1.2.8
|
|
63
|
+
|
|
64
|
+
* StringScanner#each changed to compare `cbs' keys with @matched by number in ruby 1.8 and by first character in ruby 1.9, since ?x in 1.9 returns string instead of a charcode
|
|
65
|
+
* Updated LibXML::XML::XPath to search elements with multiple classes
|
|
66
|
+
|
|
67
|
+
##### Version 1.2.7
|
|
68
|
+
|
|
69
|
+
* String#hl and #ghl: console-highlight pattern in string
|
|
70
|
+
* True#call and False#call in order to pass boolean values as callable argument
|
|
71
|
+
* ActiveRecord::Relation#any? and #empty?, ActiveRecord::Base.insert_unless_exist (using execute) and .select_rand
|
|
72
|
+
* Added couple of handlers into Array#method_missing
|
|
73
|
+
* File.modify now can process files by glob-patterns and correctly use multiple gsub! inside passed block
|
|
74
|
+
* RMTools.read now can read from list of files in order
|
|
75
|
+
* Upped RMTools.timer accuracy
|
|
76
|
+
* Optimized Array#-, #+, #& and #| for when one of arrays is empty; added Array#diff
|
|
77
|
+
* Optimized Object#to_json and String#from_json: use JSON stdlib for ruby 1.9. Object#to_json_safe: timeout'ed conversion
|
|
78
|
+
* String#cut_line and #split_to_lines optimized for use in Ruby 1.9
|
|
79
|
+
* Removed String#bytes because it duplicate ruby 1.9 method
|
|
80
|
+
* static VALUE rb_ary_count_items moved from Array#count to Array#arrange
|
|
81
|
+
* Fixed Module#self_name
|
|
82
|
+
* RMTools::CodeReader is still unstable though
|
|
83
|
+
|
|
84
|
+
##### Version 1.2.0
|
|
85
|
+
|
|
86
|
+
* Renamed debug/ to dev/, slightly restructured lib/rmtools/ and require handlers: requrie 'rmtools' for common applications and 'rmtools_dev' for irb and maybe dev environment
|
|
87
|
+
* Slightly extended StringScanner
|
|
88
|
+
* Proof of concept: Regexp reverse (wonder if someone did it earlier in Ruby)
|
|
89
|
+
* Kernel#whose? to find classes and/or modules knowing some method
|
|
90
|
+
* Method code lookup over all loaded libs (it can't handle evals yet), see dev/code_reading.rb
|
|
91
|
+
* Coloring is now made by singleton `Painter' and have option for transparent coloring
|
|
92
|
+
|
|
93
|
+
##### Version 1.1.14
|
|
94
|
+
|
|
95
|
+
* Added caller level option (:caller => <int>) for Logger
|
|
96
|
+
* Fixed trace formatting (for sure for this time)
|
|
97
|
+
* Array iterator #sum_<method> now takes argument for #sum as first argument
|
|
98
|
+
* Completed Binding#inspect_env components
|
|
99
|
+
|
|
100
|
+
##### Version 1.1.11
|
|
101
|
+
|
|
102
|
+
* Fixed Hash#unify_keys for 1.9.2
|
|
103
|
+
* Speeded Array#uniq_by up
|
|
104
|
+
* Added some shortcut methods for ActiveRecord::Base
|
|
105
|
+
|
|
106
|
+
##### Version 1.1.10
|
|
107
|
+
|
|
108
|
+
* Deleted String#to_proc. It's anyway inconsistent and causes bug in ActiveRecord 3.0.5 Base#interpolate_and_sanitize_sql and potentially somewhere else
|
|
109
|
+
* Solved problem with String#sub methods in 1.9: that's associated with String#to_hash in some mystic way. #to_hash is now #to_params
|
|
110
|
+
* Some bugfixes for previous updates
|
|
111
|
+
|
|
112
|
+
##### Version 1.1.7
|
|
113
|
+
|
|
114
|
+
* Cosmetic fixes for txts here
|
|
115
|
+
|
|
116
|
+
##### Version 1.1.6
|
|
117
|
+
|
|
118
|
+
* Rewrited few functions
|
|
119
|
+
* Fixed bug with RDoc and RI
|
|
120
|
+
* Compatible with 1.9
|
|
121
|
+
* Binding#start_interaction and RMTools::Observer for debugging purposes
|
|
122
|
+
* To require any file from lib/rmtools now RMTools::require is used
|
|
123
|
+
* In order to not overload Rails apps initialization tracing is lightened and gem now may be also required as "rmtools_nodebug" and "rmtools_notrace"
|
|
124
|
+
|
|
125
|
+
##### Version 1.1.0
|
|
126
|
+
|
|
127
|
+
* Fixed some bugs
|
|
128
|
+
* Divided by semantics
|
|
129
|
+
* Compatible with ruby 1.8.7 (2010-08-16 patchlevel 302)
|
|
130
|
+
|
|
131
|
+
##### Version 1.0.0
|
|
132
|
+
|
|
133
|
+
* Divided by classes and packed as gem
|
|
134
|
+
|
|
135
|
+
### License
|
|
136
|
+
|
|
137
|
+
RMTools is copyright (c) 2010-2013 Sergey Baev <tinbka@gmail.com>, and released under the terms of the Ruby license.
|
data/Rakefile
CHANGED
|
@@ -2,18 +2,17 @@ require 'rake'
|
|
|
2
2
|
require './lib/rmtools/install'
|
|
3
3
|
compile_manifest
|
|
4
4
|
|
|
5
|
-
RMTOOLS_VERSION = '1.
|
|
5
|
+
RMTOOLS_VERSION = '1.3.0'
|
|
6
6
|
begin
|
|
7
7
|
require 'hoe'
|
|
8
|
-
config = Hoe.spec 'rmtools' do
|
|
9
|
-
developer("Sergey Baev", "tinbka@gmail.com")
|
|
8
|
+
config = Hoe.spec 'rmtools' do |h|
|
|
9
|
+
h.developer("Sergey Baev", "tinbka@gmail.com")
|
|
10
10
|
|
|
11
|
-
self.summary = 'Yet another Ruby applied lib'
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
self.urls = ['https://github.com/tinbka/rmtools']
|
|
11
|
+
#self.summary = 'Yet another Ruby applied lib'
|
|
12
|
+
h.description = 'Applied library primarily for debug and text/arrays/files processing purposes.'
|
|
13
|
+
h.urls = ['https://github.com/tinbka/rmtools']
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
h.extra_deps = [['rake','>= 0.8.7'], ['activesupport','>= 2.3.8']]
|
|
17
16
|
end
|
|
18
17
|
config.spec.extensions << 'ext/extconf.rb'
|
|
19
18
|
rescue LoadError
|
data/lib/rmtools/core/class.rb
CHANGED
|
@@ -2,14 +2,20 @@
|
|
|
2
2
|
class Class
|
|
3
3
|
|
|
4
4
|
# define python-style initializer
|
|
5
|
+
# p = Post()
|
|
6
|
+
# p = Post user_id: 10
|
|
5
7
|
def __init__
|
|
6
|
-
|
|
7
|
-
classname
|
|
8
|
-
mod = '::'.in(name) ? eval(
|
|
9
|
-
mod.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
path = name.split('::')
|
|
9
|
+
classname = path[-1]
|
|
10
|
+
mod = '::'.in(name) ? eval(path[0..-2]*'::') : RMTools
|
|
11
|
+
if mod.is Module
|
|
12
|
+
mod.module_eval "def #{classname} *args; #{name}.new *args end
|
|
13
|
+
module_function :#{classname}"
|
|
14
|
+
if mod != RMTools
|
|
15
|
+
mod.each_child {|c| c.class_eval "include #{mod}; extend #{mod}" if !c.in c.children}
|
|
16
|
+
end
|
|
17
|
+
else
|
|
18
|
+
mod.class_eval "def #{classname} *args; #{name}.new *args end"
|
|
13
19
|
end
|
|
14
20
|
end
|
|
15
21
|
|
data/lib/rmtools/core/kernel.rb
CHANGED
data/lib/rmtools/core/object.rb
CHANGED
|
@@ -48,6 +48,31 @@ class Object
|
|
|
48
48
|
container.size == 1 ? container[0].include?(self) : container.include?(self)
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
+
def inspect_instance_variables
|
|
52
|
+
instance_eval {binding().inspect_instance_variables}
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# def result_of_hard_calculation
|
|
56
|
+
# ifndef {... hard_calculation ...}
|
|
57
|
+
# end
|
|
58
|
+
# ==
|
|
59
|
+
# def result_of_hard_calculation
|
|
60
|
+
# if defined? @result_of_hard_calculation
|
|
61
|
+
# return @result_of_hard_calculation
|
|
62
|
+
# else
|
|
63
|
+
# ... hard_calculation
|
|
64
|
+
# res = ...
|
|
65
|
+
# @result_of_hard_calculation = res
|
|
66
|
+
# end
|
|
67
|
+
# end
|
|
68
|
+
def ifndef(ivar=caller(1)[0].parse(:caller).func)
|
|
69
|
+
ivar = :"@#{ivar}"
|
|
70
|
+
return instance_variable_get ivar if instance_variable_defined? ivar
|
|
71
|
+
instance_variable_set ivar, yield
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
51
76
|
def deep_clone
|
|
52
77
|
_deep_clone({})
|
|
53
78
|
end
|
|
@@ -83,11 +83,12 @@ module ActiveRecord
|
|
|
83
83
|
SELECT @cnt:=#{cnt ? cnt.to_i : 'COUNT(*)'}+1#{-discnt.to_i if discnt}, @lim:=#{limit.to_i}#{" FROM #{cnt_tables} WHERE #{cnt_where}" if !cnt}
|
|
84
84
|
) vars
|
|
85
85
|
STRAIGHT_JOIN (
|
|
86
|
-
SELECT #{fields}, @lim:=@lim-1 FROM #{tables} WHERE (@cnt:=@cnt-1) AND RAND() < @lim/@cnt
|
|
86
|
+
SELECT #{fields}, @lim:=@lim-1 FROM #{tables} WHERE #{"(#{_where}) AND " if _where} (@cnt:=@cnt-1) AND RAND() < @lim/@cnt
|
|
87
87
|
) i", options])
|
|
88
88
|
end
|
|
89
89
|
|
|
90
90
|
class_attribute :enums
|
|
91
|
+
# virtual (only-in-ruby) "enum" type support
|
|
91
92
|
def enum hash
|
|
92
93
|
key = hash.keys.first
|
|
93
94
|
(self.enums ||= {}).merge! hash
|
|
@@ -101,9 +102,33 @@ module ActiveRecord
|
|
|
101
102
|
write_attribute('#{key}', Fixnum === val ? val : self.class.enums[:#{key}].index val.to_s
|
|
102
103
|
end
|
|
103
104
|
}
|
|
104
|
-
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# usable to define shortcut-scopes on class with number of boolean flags: #admin, #open, #removed, etc
|
|
108
|
+
def boolean_scopes!
|
|
109
|
+
columns.select_by_type(:boolean).names.to_syms.each {|col|
|
|
110
|
+
unless respond_to? col
|
|
111
|
+
scope col, where("#{quoted_table_name}.#{col} = 1")
|
|
112
|
+
end
|
|
113
|
+
}
|
|
114
|
+
rescue
|
|
115
|
+
nil
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# more universal version of boolean_scopes! that helps to find records with any non-null values,
|
|
119
|
+
# including zero and empty string
|
|
120
|
+
def non_null_scopes!
|
|
121
|
+
boolean_scopes!
|
|
122
|
+
columns.names.to_syms.each {|col|
|
|
123
|
+
unless respond_to? col
|
|
124
|
+
scope col, where("#{quoted_table_name}.#{col} is not null")
|
|
125
|
+
end
|
|
126
|
+
}
|
|
127
|
+
rescue
|
|
128
|
+
nil
|
|
129
|
+
end
|
|
105
130
|
|
|
106
|
-
|
|
131
|
+
end
|
|
107
132
|
|
|
108
133
|
# fix for thinking_sphinx equation in #instances_from_class:
|
|
109
134
|
# ids.collect {|obj_id| instances.detect do |obj| obj.primary_key_for_sphinx == obj_id end}
|
|
@@ -56,10 +56,10 @@ module RMTools
|
|
|
56
56
|
def format_trace_to_html(a)
|
|
57
57
|
a.map! do |lines|
|
|
58
58
|
caller_string, snippet = lines/"\n"
|
|
59
|
-
|
|
60
|
-
if
|
|
61
|
-
path =
|
|
62
|
-
lines = ["<a href='#{CGI.escape 'file://'+path}'>#{path}</a>:#{
|
|
59
|
+
caler = caller_string.parse(:caller)
|
|
60
|
+
if caler
|
|
61
|
+
path = caler.path
|
|
62
|
+
lines = ["<a href='#{CGI.escape 'file://'+path}'>#{path}</a>:#{caler.line} in #{caler.func}"]
|
|
63
63
|
lines << RMTools::Painter.clean(snippet) if snippet
|
|
64
64
|
lines * "\n"
|
|
65
65
|
else
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
module Enumerable
|
|
3
3
|
|
|
4
|
+
def to_traversable
|
|
5
|
+
RMTools::ValueTraversable(to_a)
|
|
6
|
+
end
|
|
7
|
+
|
|
4
8
|
def import(arr, index)
|
|
5
9
|
self[index] = arr[index]
|
|
6
10
|
end
|
|
@@ -26,7 +30,7 @@ module Enumerable
|
|
|
26
30
|
res
|
|
27
31
|
end
|
|
28
32
|
|
|
29
|
-
def
|
|
33
|
+
def recursive_select(&b)
|
|
30
34
|
res = []
|
|
31
35
|
to_a.each {|e|
|
|
32
36
|
res << e if b[e]
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
require 'active_support/core_ext/hash'
|
|
3
|
+
RMTools::require 'enumerable/traversal'
|
|
3
4
|
|
|
4
5
|
class Hash
|
|
6
|
+
include RMTools::KeyValueTraversal
|
|
5
7
|
alias :>> :reverse_merge!
|
|
6
8
|
|
|
9
|
+
def to_traversable
|
|
10
|
+
RMTools::KeyValueTraversable.new(self)
|
|
11
|
+
end
|
|
12
|
+
|
|
7
13
|
def +(other_hash)
|
|
8
14
|
merge(other_hash || {})
|
|
9
15
|
end
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
module RMTools
|
|
2
|
+
|
|
3
|
+
# It's included into Dir and could also be included into Enumerable
|
|
4
|
+
# Though we don't do latter automatically, because Enumerable as it is overloaded of a bunch of questionable methods
|
|
5
|
+
module ValueTraversal
|
|
6
|
+
|
|
7
|
+
def preorder_traverse(&b)
|
|
8
|
+
next_level = RMTools::ValueTraversable.new
|
|
9
|
+
to_traversable.each {|e|
|
|
10
|
+
if e.respond_to? :preorder_traverse
|
|
11
|
+
next_level += e
|
|
12
|
+
else
|
|
13
|
+
b[e]
|
|
14
|
+
end
|
|
15
|
+
}
|
|
16
|
+
next_level.preorder_traverse(&b) if next_level.any?
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def depth_first_traverse(&b)
|
|
20
|
+
to_traversable.flatten.each &b
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def preorder_find(&b)
|
|
24
|
+
next_level = RMTools::ValueTraversable.new
|
|
25
|
+
to_traversable.each {|e|
|
|
26
|
+
if e.respond_to? :preorder_find
|
|
27
|
+
next_level += e
|
|
28
|
+
else
|
|
29
|
+
return e if b[e]
|
|
30
|
+
end
|
|
31
|
+
}
|
|
32
|
+
next_level.preorder_find(&b) if next_level.any?
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def depth_first_find(&b)
|
|
36
|
+
to_traversable.each {|e|
|
|
37
|
+
if v.respond_to? :depth_first_find
|
|
38
|
+
if res = e.depth_first_find(&b)
|
|
39
|
+
return res
|
|
40
|
+
end
|
|
41
|
+
else
|
|
42
|
+
return e if b[e]
|
|
43
|
+
end
|
|
44
|
+
}
|
|
45
|
+
nil
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def preorder_select
|
|
49
|
+
res = []; preorder_traverse {|e| res << e if yield(e)}; res
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def depth_first_select
|
|
53
|
+
res = []; depth_first_traverse {|e| res << e if yield(e)}; res
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def depth_first_map(&b)
|
|
57
|
+
to_traversable.map {|e|
|
|
58
|
+
if e.respond_to? :depth_map
|
|
59
|
+
e.depth_map &b
|
|
60
|
+
else
|
|
61
|
+
b[e]
|
|
62
|
+
end
|
|
63
|
+
}
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Presumptions:
|
|
69
|
+
# all keys (at least on the same depth) are uniq
|
|
70
|
+
# values are either enumerable or nothing
|
|
71
|
+
#
|
|
72
|
+
# It's included into Hash
|
|
73
|
+
module KeyValueTraversal
|
|
74
|
+
|
|
75
|
+
def preorder_traverse(&b)
|
|
76
|
+
next_level = RMTools::KeyValueTraversable.new
|
|
77
|
+
to_traversal.each {|k, v|
|
|
78
|
+
b[k]
|
|
79
|
+
if v.respond_to? :preorder_traverse
|
|
80
|
+
next_level += v
|
|
81
|
+
end
|
|
82
|
+
}
|
|
83
|
+
next_level.preorder_traverse(&b) if next_level.any?
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def depth_first_traverse(&b)
|
|
87
|
+
to_traversal.each {|k, v|
|
|
88
|
+
b[k]
|
|
89
|
+
if v.respond_to? :depth_first_traverse
|
|
90
|
+
v.depth_first_traverse &b
|
|
91
|
+
end
|
|
92
|
+
}
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def preorder_find(&b)
|
|
96
|
+
next_level = RMTools::KeyValueTraversable.new
|
|
97
|
+
to_traversal.each {|k, v|
|
|
98
|
+
return k if b[k]
|
|
99
|
+
if v.respond_to? :preorder_find
|
|
100
|
+
next_level += v
|
|
101
|
+
end
|
|
102
|
+
}
|
|
103
|
+
next_level.preorder_find(&b) if next_level.any?
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def depth_first_find(&b)
|
|
107
|
+
to_traversal.each {|k, v|
|
|
108
|
+
return k if b[k]
|
|
109
|
+
if v.respond_to?(:depth_first_traverse) and res = v.depth_first_traverse(&b)
|
|
110
|
+
return res
|
|
111
|
+
end
|
|
112
|
+
}
|
|
113
|
+
nil
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def preorder_select
|
|
117
|
+
res = []; preorder_traverse {|k, v| res << k if yield(k)}; res
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def depth_first_select
|
|
121
|
+
res = []; depth_first_traverse {|k, v| res << k if yield(k)}; res
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
class ValueTraversable < Array
|
|
127
|
+
include ValueTraversal
|
|
128
|
+
__init__ if respond_to? :__init__
|
|
129
|
+
|
|
130
|
+
private
|
|
131
|
+
alias :array_plus :+
|
|
132
|
+
public
|
|
133
|
+
|
|
134
|
+
def +(enum)
|
|
135
|
+
if Hash === enum
|
|
136
|
+
enum = enum.values
|
|
137
|
+
end
|
|
138
|
+
array_plus enum.to_traversable
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def to_traversable
|
|
142
|
+
self
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
class KeyValueTraversable < Hash
|
|
147
|
+
include KeyValueTraversal
|
|
148
|
+
__init__ if respond_to? :__init__
|
|
149
|
+
|
|
150
|
+
def +(enum)
|
|
151
|
+
if Hash === enum
|
|
152
|
+
merge enum.to_traversable
|
|
153
|
+
else
|
|
154
|
+
values.to_traversable.concat enum.to_traversable
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def to_traversable
|
|
159
|
+
self
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
end
|
|
164
|
+
|
data/lib/rmtools/fs/dir.rb
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
RMTools::require 'fs/file'
|
|
3
|
+
RMTools::require 'enumerable/traversal'
|
|
3
4
|
|
|
4
5
|
class Dir
|
|
6
|
+
# included in order to use treeish search in directory content tree
|
|
7
|
+
include RMTools::ValueTraversal
|
|
8
|
+
|
|
9
|
+
def to_traversable
|
|
10
|
+
RMTools::ValueTraversable.new(children)
|
|
11
|
+
end
|
|
5
12
|
|
|
6
13
|
def include?(name)
|
|
7
14
|
#content.map {|f| File.split(f)[1]}.include? name
|
|
@@ -12,9 +19,9 @@ class Dir
|
|
|
12
19
|
list = []
|
|
13
20
|
cont = content.map {|f|
|
|
14
21
|
if File.directory?(f)
|
|
15
|
-
rc = Dir.new(f).recursive_content
|
|
22
|
+
rc = Dir.new(f).recursive_content(flat)
|
|
16
23
|
flat ? list.concat(rc) : rc
|
|
17
|
-
else flat ? (list << f) : f
|
|
24
|
+
else flat ? (list << f.sub(/^\.\//, '')) : f.sub(/^\.\//, '')
|
|
18
25
|
end
|
|
19
26
|
}
|
|
20
27
|
(flat ? list : cont)
|
data/lib/rmtools/fs/io.rb
CHANGED
|
@@ -12,21 +12,26 @@ class IO
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
module RMTools
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
|
|
16
|
+
def self.prepare_write(df, value)
|
|
17
|
+
return false if value.nil?
|
|
18
|
+
value = value.inspect unless value.class == String
|
|
19
|
+
value = value.force_encoding('UTF-8') if RUBY_VERSION > '1.9'
|
|
20
|
+
df = df.tr '\\', '/'
|
|
21
|
+
path = File.dirname(df)
|
|
22
|
+
FileUtils.mkpath(path) if !File.directory?(path)
|
|
23
|
+
yield df, value
|
|
24
|
+
value.size
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def rw(df, value=nil)
|
|
28
|
+
RMTools::prepare_write df, value do
|
|
21
29
|
File.open(df, File::CREAT|File::WRONLY|File::TRUNC) {|f| f << value}
|
|
22
|
-
value.size
|
|
23
30
|
end
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
path = File.dirname(df)
|
|
29
|
-
FileUtils.mkpath(path) if !File.directory?(path)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def write(df, value='', pos=0)
|
|
34
|
+
RMTools::prepare_write df, value do
|
|
30
35
|
if pos == 0
|
|
31
36
|
File.open(df, File::CREAT|File::WRONLY|File::APPEND) {|f| f << value}
|
|
32
37
|
else
|
|
@@ -40,8 +45,8 @@ module RMTools
|
|
|
40
45
|
end
|
|
41
46
|
File.open(df, File::CREAT|File::WRONLY) {|f| f.pos = pos; f << value}
|
|
42
47
|
end
|
|
43
|
-
value.size
|
|
44
48
|
end
|
|
49
|
+
end
|
|
45
50
|
|
|
46
51
|
# read('filename')
|
|
47
52
|
### => 'text from filename'
|
data/lib/rmtools/lang/ansi.rb
CHANGED
|
@@ -7,10 +7,12 @@ module RMTools
|
|
|
7
7
|
module Cyrillic
|
|
8
8
|
RU_LETTERS = "абвгдеёжзийклмнопрстуфхцчшщьыъэюя", "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЬЫЪЭЮЯ"
|
|
9
9
|
|
|
10
|
+
ANSI_LETTERS_UC = ["\270\340-\377", "\250\300-\337"]
|
|
11
|
+
ANSI_LETTERS_DC = ANSI_LETTERS_UC.reverse
|
|
12
|
+
ANSI_YOYE = ["\270\250", "\345\305"]
|
|
10
13
|
if RUBY_VERSION > '1.9'
|
|
11
|
-
ANSI_LETTERS_UC
|
|
12
|
-
|
|
13
|
-
ANSI_YOYE = ["\270\250", "\345\305"].force_encodings "Windows-1251"
|
|
14
|
+
ANSI_LETTERS_UC.force_encodings "Windows-1251"
|
|
15
|
+
ANSI_YOYE.force_encodings "Windows-1251"
|
|
14
16
|
ANSI_ENCODING = ANSI_LETTERS_UC[0].encoding
|
|
15
17
|
end
|
|
16
18
|
end
|
|
@@ -17,6 +17,52 @@ class String
|
|
|
17
17
|
self !~ /[^А-пр-ёЁ]/
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
+
def cupcase
|
|
21
|
+
encoding != ANSI_ENCODING ?
|
|
22
|
+
ANSI2UTF[UTF2ANSI[self].tr(*ANSI_LETTERS_UC)] :
|
|
23
|
+
tr(*ANSI_LETTERS_UC)
|
|
24
|
+
end
|
|
25
|
+
def cupcase!
|
|
26
|
+
encoding != ANSI_ENCODING ?
|
|
27
|
+
ANSI2UTF[UTF2ANSI[self].tr!(*ANSI_LETTERS_UC)] :
|
|
28
|
+
tr!(*ANSI_LETTERS_UC)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def cdowncase
|
|
32
|
+
encoding != ANSI_ENCODING ?
|
|
33
|
+
ANSI2UTF[UTF2ANSI[self].tr(*ANSI_LETTERS_DC)] :
|
|
34
|
+
tr(*ANSI_LETTERS_DC)
|
|
35
|
+
end
|
|
36
|
+
def cdowncase!
|
|
37
|
+
encoding != ANSI_ENCODING ?
|
|
38
|
+
ANSI2UTF[UTF2ANSI[self].tr!(*ANSI_LETTERS_DC)] :
|
|
39
|
+
tr!(*ANSI_LETTERS_DC)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def rmumlaut
|
|
43
|
+
encoding != ANSI_ENCODING ?
|
|
44
|
+
ANSI2UTF[UTF2ANSI[self].tr(*ANSI_YOYE)] :
|
|
45
|
+
tr(*ANSI_YOYE)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# full upcase, because cdowncase doesn't convert non-cyrillic
|
|
49
|
+
def fupcase
|
|
50
|
+
upcase.cupcase
|
|
51
|
+
end
|
|
52
|
+
def fupcase!
|
|
53
|
+
res = upcase!
|
|
54
|
+
cupcase! or res
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# full downcase, because cdowncase doesn't convert non-cyrillic
|
|
58
|
+
def fdowncase
|
|
59
|
+
downcase.cdowncase
|
|
60
|
+
end
|
|
61
|
+
def fdowncase!
|
|
62
|
+
res = downcase!
|
|
63
|
+
cdowncase! or res
|
|
64
|
+
end
|
|
65
|
+
|
|
20
66
|
if RUBY_VERSION > "1.9"
|
|
21
67
|
|
|
22
68
|
def translit
|
|
@@ -31,33 +77,18 @@ class String
|
|
|
31
77
|
tr "`qwertyuiop[]asdfghjkl;:'zxcvbnm,./|?\"@\#$^&~QWERTYUIOP{}ASDFGHJKLZXCVBNM<>", "ёйцукенгшщзхъфывапролджЖэячсмитьбю./,Э\"№;:?ЁЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЯЧСМИТЬБЮ"
|
|
32
78
|
end
|
|
33
79
|
|
|
34
|
-
def
|
|
35
|
-
|
|
36
|
-
ANSI2UTF[UTF2ANSI[self].tr(*ANSI_LETTERS_UC)]:
|
|
37
|
-
tr(*ANSI_LETTERS_UC)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def cdowncase
|
|
41
|
-
encoding != ANSI_ENCODING ?
|
|
42
|
-
ANSI2UTF[UTF2ANSI[self].tr(*ANSI_LETTERS_DC)]:
|
|
43
|
-
tr(*ANSI_LETTERS_DC)
|
|
80
|
+
def ccap
|
|
81
|
+
self[0].cupcase + self[1..-1]
|
|
44
82
|
end
|
|
45
83
|
|
|
46
84
|
def cuncap
|
|
47
85
|
self[0].cdowncase + self[1..-1]
|
|
48
86
|
end
|
|
49
|
-
|
|
50
|
-
def rmumlaut
|
|
51
|
-
encoding != ANSI_ENCODING ?
|
|
52
|
-
ANSI2UTF[UTF2ANSI[self].tr(*ANSI_YOYE)]:
|
|
53
|
-
tr(*ANSI_YOYE)
|
|
54
|
-
end
|
|
55
87
|
|
|
56
88
|
alias csize size
|
|
57
89
|
alias cljust ljust
|
|
58
90
|
alias cjust rjust
|
|
59
91
|
alias ccenter center
|
|
60
|
-
alias ccap capitalize
|
|
61
92
|
alias csqueeze squeeze
|
|
62
93
|
|
|
63
94
|
def ci; self end
|
|
@@ -84,18 +115,6 @@ class String
|
|
|
84
115
|
ANSI2UTF[UTF2ANSI[self].center(*args)]
|
|
85
116
|
end
|
|
86
117
|
|
|
87
|
-
def cupcase(encode=1)
|
|
88
|
-
encode ?
|
|
89
|
-
ANSI2UTF[UTF2ANSI[self].tr("\270\340-\377", "\250\300-\337")]:
|
|
90
|
-
tr("\270\340-\377", "\250\300-\337")
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
def cdowncase(encode=1)
|
|
94
|
-
encode ?
|
|
95
|
-
ANSI2UTF[UTF2ANSI[self].tr("\250\300-\337", "\270\340-\377")]:
|
|
96
|
-
tr("\250\300-\337", "\270\340-\377")
|
|
97
|
-
end
|
|
98
|
-
|
|
99
118
|
def ccap(encode=1)
|
|
100
119
|
self[0,2].cupcase(encode) + self[2..-1]
|
|
101
120
|
end
|
|
@@ -108,12 +127,6 @@ class String
|
|
|
108
127
|
ANSI2UTF[UTF2ANSI[self].squeeze]
|
|
109
128
|
end
|
|
110
129
|
|
|
111
|
-
def rmumlaut(encode=1)
|
|
112
|
-
encode ?
|
|
113
|
-
ANSI2UTF[UTF2ANSI[self].tr("\270\250", "\345\305")]:
|
|
114
|
-
tr("\270\250", "\345\305")
|
|
115
|
-
end
|
|
116
|
-
|
|
117
130
|
def ru2en
|
|
118
131
|
gsub("ё", "`").gsub("й", "q").gsub("ц", "w").gsub("у", "e").gsub("к", "r").gsub("е", "t").gsub("н", "y").gsub("г", "u").gsub("ш", "i").gsub("щ", "o").gsub("з", "p").gsub("х", "[").gsub("ъ", "]").gsub("ф", "a").gsub("ы", "s").gsub("в", "d").gsub("а", "f").gsub("п", "g").gsub("р", "h").gsub("о", "j").gsub("л", "k").gsub("д", "l").gsub("э", "'").gsub("я", "z").gsub("ч", "x").gsub("с", "c").gsub("м", "v").gsub("и", "b").gsub("т", "n").gsub("ь", "m").gsub("/", "|").gsub(".", "/").gsub("ю", ".").gsub("?", "&").gsub(",", "?").gsub("б", ",").gsub("\"", "@").gsub("№", "#").gsub(";", "$").gsub(":", "^").gsub("ж", ";").gsub("Ё", "~").gsub("Й", "Q").gsub("Ц", "W").gsub("У", "E").gsub("К", "R").gsub("Е", "T").gsub("Н", "Y").gsub("Г", "U").gsub("Ш", "I").gsub("Щ", "O").gsub("З", "P").gsub("Х", "{").gsub("Ъ", "}").gsub("Ф", "A").gsub("Ы", "S").gsub("В", "D").gsub("А", "F").gsub("П", "G").gsub("Р", "H").gsub("О", "J").gsub("Л", "K").gsub("Д", "L").gsub("Ж", ":").gsub("Э", "\"").gsub("Я", "Z").gsub("Ч", "X").gsub("С", "C").gsub("М", "V").gsub("И", "B").gsub("Т", "N").gsub("Ь", "M").gsub("Б", "<").gsub("Ю", ">")
|
|
119
132
|
end
|
|
@@ -2,14 +2,20 @@
|
|
|
2
2
|
RMTools::require 'conversions/string'
|
|
3
3
|
|
|
4
4
|
class String
|
|
5
|
-
CALLER_RE =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
SIMPLE_CALLER_RE =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
CALLER_RE = %r{^(.*?([^/\\]+?))#{ # ( path ( file ) )
|
|
6
|
+
}:(\d+)(?::in #{ # :( line )[ :in
|
|
7
|
+
}`(block (?:\((\d+) levels\) )?in )?(.+?)'#{ # `[ block in ] ( closure )' ]
|
|
8
|
+
})?$}
|
|
9
|
+
SIMPLE_CALLER_RE = %r{^(.*?([^/\\]+?))#{ # ( path ( file ) )
|
|
10
|
+
}:(\d+)(?::in #{ # :( line )[ :in
|
|
11
|
+
}`(.+?)'#{ # `( closure )' ]
|
|
12
|
+
})?$}
|
|
13
|
+
JS_CALLER_RE = %r{^(?:(\S*)[\s@])?\(?(?:[^:]+://#{ # ( func ) (protocol
|
|
14
|
+
}[^/:]*(?::\d+)?)?#{ # root[:port]
|
|
15
|
+
}/([^?#]*?\/(\w+(?:\.\w+)?)#{ # ( path/( file[ .fileext ] )
|
|
16
|
+
}(?:\?.*?)?)#{ # [ ?query ] )
|
|
17
|
+
}:(\d+)?(?::(\d+))?#{ # :( line ):( char ))
|
|
18
|
+
}\)?$}
|
|
13
19
|
URL_RE = %r{^((?:([^:]+)://)#{ # ( protocol
|
|
14
20
|
}([^/:]*(?::(\d+))?))?#{ # root[:port] )
|
|
15
21
|
}((/[^?#]*?(?:\.(\w+))?)#{ # ( path[.( fileext )]
|
|
@@ -47,6 +53,15 @@ class String
|
|
|
47
53
|
'fullpath' => m[1] =~ /[\(\[]/ ?
|
|
48
54
|
m[1] :
|
|
49
55
|
File.expand_path(m[1]) }
|
|
56
|
+
when :js_caller
|
|
57
|
+
m = match JS_CALLER_RE
|
|
58
|
+
!m || m[0].empty? ? nil :
|
|
59
|
+
{ 'func' => m[1],
|
|
60
|
+
'fullpath' => m[2],
|
|
61
|
+
'file' => m[3],
|
|
62
|
+
'line' => m[4] && m[4].to_i,
|
|
63
|
+
'char' => m[5] && m[5].to_i,
|
|
64
|
+
'from' => m[3..5].compact*':' }
|
|
50
65
|
when :ip; self[IP_RE]
|
|
51
66
|
when :ip_range; (m = match IP_RANGE_RE) && m[1]..m[2]
|
|
52
67
|
else raise ArgumentError, "Incorrect flag. Correct flags: :uri, :caller, :ip, :ip_range"
|
|
@@ -79,6 +79,7 @@ class String
|
|
|
79
79
|
#end
|
|
80
80
|
#
|
|
81
81
|
# this method defined in Enumerable and returns Enumerable::Enumerator that should be converted to array of integers, not hex-strings
|
|
82
|
+
|
|
82
83
|
if RUBY_VERSION < '1.9'
|
|
83
84
|
def symbols_count
|
|
84
85
|
unpack('U*').size
|
|
@@ -89,4 +90,31 @@ class String
|
|
|
89
90
|
end
|
|
90
91
|
end
|
|
91
92
|
|
|
93
|
+
|
|
94
|
+
# make simple strings readable by FTS engines and make results more cacheable by key-value dbs
|
|
95
|
+
def to_search
|
|
96
|
+
gsub(/[\0-\/:-@\[-`{-~ \s]/, ' ').strip.squeeze(' ').fdowncase
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# remove empty strings from html output
|
|
100
|
+
def squeeze_newlines
|
|
101
|
+
gsub(/\s+\n+/, "\n").squeeze("\n")
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# polymorphic helper
|
|
105
|
+
def recordize(whiny=true)
|
|
106
|
+
classname, id = split('#')
|
|
107
|
+
unless id
|
|
108
|
+
if whiny
|
|
109
|
+
raise ArgumentError, "Could not find record by string: #{inspect}"
|
|
110
|
+
else return false
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
model = classname.constantize
|
|
114
|
+
model.respond_to?(:get) ?
|
|
115
|
+
model.get(id) :
|
|
116
|
+
model.where(:id => id).first
|
|
117
|
+
end
|
|
118
|
+
alias :to_record :recordize
|
|
119
|
+
|
|
92
120
|
end
|
data/lib/rmtools.so
ADDED
|
Binary file
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rmtools
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.3.0
|
|
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: 2013-
|
|
12
|
+
date: 2013-03-11 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rake
|
|
@@ -66,7 +66,7 @@ dependencies:
|
|
|
66
66
|
requirements:
|
|
67
67
|
- - ~>
|
|
68
68
|
- !ruby/object:Gem::Version
|
|
69
|
-
version: '3.
|
|
69
|
+
version: '3.5'
|
|
70
70
|
type: :development
|
|
71
71
|
prerelease: false
|
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -74,7 +74,7 @@ dependencies:
|
|
|
74
74
|
requirements:
|
|
75
75
|
- - ~>
|
|
76
76
|
- !ruby/object:Gem::Version
|
|
77
|
-
version: '3.
|
|
77
|
+
version: '3.5'
|
|
78
78
|
description: Applied library primarily for debug and text/arrays/files processing
|
|
79
79
|
purposes.
|
|
80
80
|
email:
|
|
@@ -83,107 +83,111 @@ executables: []
|
|
|
83
83
|
extensions:
|
|
84
84
|
- ext/extconf.rb
|
|
85
85
|
extra_rdoc_files:
|
|
86
|
-
-
|
|
87
|
-
-
|
|
88
|
-
-
|
|
86
|
+
- License.txt
|
|
87
|
+
- README.txt
|
|
88
|
+
- Manifest.txt
|
|
89
89
|
files:
|
|
90
|
-
-
|
|
91
|
-
-
|
|
92
|
-
-
|
|
93
|
-
- lib/rmtools.
|
|
94
|
-
- lib/rmtools/
|
|
95
|
-
- lib/rmtools/
|
|
96
|
-
- lib/rmtools/
|
|
90
|
+
- License.txt
|
|
91
|
+
- README.txt
|
|
92
|
+
- lib/rmtools_dev.rb
|
|
93
|
+
- lib/rmtools.so
|
|
94
|
+
- lib/rmtools/core/module.rb
|
|
95
|
+
- lib/rmtools/core/js.rb
|
|
96
|
+
- lib/rmtools/core/string_compliance.rb
|
|
97
|
+
- lib/rmtools/core/kernel.rb
|
|
98
|
+
- lib/rmtools/core/arguments.rb
|
|
99
|
+
- lib/rmtools/core/object.rb
|
|
100
|
+
- lib/rmtools/core/deprecation.rb
|
|
101
|
+
- lib/rmtools/core/aliases.rb
|
|
102
|
+
- lib/rmtools/core/proc.rb
|
|
103
|
+
- lib/rmtools/core/class.rb
|
|
104
|
+
- lib/rmtools/core/numeric.rb
|
|
105
|
+
- lib/rmtools/core/boolean.rb
|
|
106
|
+
- lib/rmtools/core/regexp.rb
|
|
107
|
+
- lib/rmtools/core/threadify.rb
|
|
108
|
+
- lib/rmtools/rand/range.rb
|
|
109
|
+
- lib/rmtools/rand/string.rb
|
|
110
|
+
- lib/rmtools/rand/array.rb
|
|
111
|
+
- lib/rmtools/rand/enum.rb
|
|
112
|
+
- lib/rmtools/db.rb
|
|
113
|
+
- lib/rmtools/install.rb
|
|
114
|
+
- lib/rmtools/conversions.rb
|
|
115
|
+
- lib/rmtools/functional.rb
|
|
116
|
+
- lib/rmtools/require.rb
|
|
117
|
+
- lib/rmtools/lang.rb
|
|
118
|
+
- lib/rmtools/time.rb
|
|
119
|
+
- lib/rmtools/fs.rb
|
|
97
120
|
- lib/rmtools/fs/dir.rb
|
|
121
|
+
- lib/rmtools/fs/file.rb
|
|
98
122
|
- lib/rmtools/fs/tools.rb
|
|
99
|
-
- lib/rmtools/
|
|
100
|
-
- lib/rmtools/ip/string.rb
|
|
101
|
-
- lib/rmtools/dev/present.rb
|
|
102
|
-
- lib/rmtools/dev/blackhole.rb
|
|
103
|
-
- lib/rmtools/dev/observing.rb
|
|
123
|
+
- lib/rmtools/fs/io.rb
|
|
104
124
|
- lib/rmtools/dev/traceback.rb
|
|
105
|
-
- lib/rmtools/dev/binding.rb
|
|
106
125
|
- lib/rmtools/dev/logging.rb
|
|
107
|
-
- lib/rmtools/dev/
|
|
108
|
-
- lib/rmtools/dev/highlight.rb
|
|
126
|
+
- lib/rmtools/dev/binding.rb
|
|
109
127
|
- lib/rmtools/dev/timer.rb
|
|
128
|
+
- lib/rmtools/dev/blackhole.rb
|
|
110
129
|
- lib/rmtools/dev/code_reader.rb
|
|
111
|
-
- lib/rmtools/
|
|
130
|
+
- lib/rmtools/dev/trace_format.rb
|
|
131
|
+
- lib/rmtools/dev/highlight.rb
|
|
132
|
+
- lib/rmtools/dev/present.rb
|
|
133
|
+
- lib/rmtools/dev/observing.rb
|
|
134
|
+
- lib/rmtools/b.rb
|
|
135
|
+
- lib/rmtools/init.rb
|
|
136
|
+
- lib/rmtools/text.rb
|
|
112
137
|
- lib/rmtools/xml/string.rb
|
|
113
|
-
- lib/rmtools/xml/libxml.rb
|
|
114
|
-
- lib/rmtools/xml/finders.rb
|
|
115
138
|
- lib/rmtools/xml/node.rb
|
|
139
|
+
- lib/rmtools/xml/xpath.rb
|
|
116
140
|
- lib/rmtools/xml/document.rb
|
|
117
|
-
- lib/rmtools/
|
|
118
|
-
- lib/rmtools/
|
|
119
|
-
- lib/rmtools/
|
|
120
|
-
- lib/rmtools/
|
|
121
|
-
- lib/rmtools/
|
|
122
|
-
- lib/rmtools/
|
|
123
|
-
- lib/rmtools/core
|
|
124
|
-
- lib/rmtools/
|
|
125
|
-
- lib/rmtools/core/threadify.rb
|
|
126
|
-
- lib/rmtools/core/module.rb
|
|
127
|
-
- lib/rmtools/core/object.rb
|
|
128
|
-
- lib/rmtools/core/deprecation.rb
|
|
129
|
-
- lib/rmtools/core/regexp.rb
|
|
130
|
-
- lib/rmtools/core/class.rb
|
|
131
|
-
- lib/rmtools/core/proc.rb
|
|
132
|
-
- lib/rmtools/lang/ansi.rb
|
|
133
|
-
- lib/rmtools/lang/regexp.rb
|
|
134
|
-
- lib/rmtools/lang/cyrillic.rb
|
|
135
|
-
- lib/rmtools/rand/string.rb
|
|
136
|
-
- lib/rmtools/rand/enum.rb
|
|
137
|
-
- lib/rmtools/rand/range.rb
|
|
138
|
-
- lib/rmtools/rand/array.rb
|
|
141
|
+
- lib/rmtools/xml/finders.rb
|
|
142
|
+
- lib/rmtools/xml/libxml.rb
|
|
143
|
+
- lib/rmtools/ip.rb
|
|
144
|
+
- lib/rmtools/dev.rb
|
|
145
|
+
- lib/rmtools/rand.rb
|
|
146
|
+
- lib/rmtools/db/active_record.rb
|
|
147
|
+
- lib/rmtools/core.rb
|
|
148
|
+
- lib/rmtools/console.rb
|
|
139
149
|
- lib/rmtools/text/string_simple.rb
|
|
150
|
+
- lib/rmtools/text/string_split.rb
|
|
140
151
|
- lib/rmtools/text/string_scanner.rb
|
|
141
152
|
- lib/rmtools/text/textilize.rb
|
|
142
153
|
- lib/rmtools/text/string_rtl.rb
|
|
143
|
-
- lib/rmtools/text/string_split.rb
|
|
144
|
-
- lib/rmtools/text/string_parse.rb
|
|
145
154
|
- lib/rmtools/text/regexp.rb
|
|
155
|
+
- lib/rmtools/text/string_parse.rb
|
|
156
|
+
- lib/rmtools/lang/cyrillic.rb
|
|
157
|
+
- lib/rmtools/lang/ansi.rb
|
|
158
|
+
- lib/rmtools/lang/regexp.rb
|
|
159
|
+
- lib/rmtools/conversions/string.rb
|
|
160
|
+
- lib/rmtools/conversions/json.rb
|
|
161
|
+
- lib/rmtools/conversions/enum.rb
|
|
162
|
+
- lib/rmtools/conversions/int.rb
|
|
146
163
|
- lib/rmtools/time/russian.rb
|
|
147
164
|
- lib/rmtools/time/global.rb
|
|
148
|
-
- lib/rmtools/
|
|
149
|
-
- lib/rmtools/
|
|
150
|
-
- lib/rmtools/
|
|
151
|
-
- lib/rmtools/
|
|
152
|
-
- lib/rmtools/
|
|
153
|
-
- lib/rmtools/db.rb
|
|
154
|
-
- lib/rmtools/fs.rb
|
|
155
|
-
- lib/rmtools/ip.rb
|
|
156
|
-
- lib/rmtools/lang.rb
|
|
157
|
-
- lib/rmtools/functional.rb
|
|
158
|
-
- lib/rmtools/install.rb
|
|
159
|
-
- lib/rmtools/functional/decorate.rb
|
|
165
|
+
- lib/rmtools/enumerable.rb
|
|
166
|
+
- lib/rmtools/dev_min.rb
|
|
167
|
+
- lib/rmtools/ip/string.rb
|
|
168
|
+
- lib/rmtools/ip/numeric.rb
|
|
169
|
+
- lib/rmtools/xml.rb
|
|
160
170
|
- lib/rmtools/functional/fold.rb
|
|
171
|
+
- lib/rmtools/functional/decorate.rb
|
|
161
172
|
- lib/rmtools/functional/unfold.rb
|
|
162
|
-
- lib/rmtools/text.rb
|
|
163
|
-
- lib/rmtools/console.rb
|
|
164
|
-
- lib/rmtools/time.rb
|
|
165
|
-
- lib/rmtools/dev.rb
|
|
166
|
-
- lib/rmtools/enumerable/common.rb
|
|
167
173
|
- lib/rmtools/enumerable/range.rb
|
|
168
|
-
- lib/rmtools/enumerable/
|
|
169
|
-
- lib/rmtools/enumerable/
|
|
174
|
+
- lib/rmtools/enumerable/traversal.rb
|
|
175
|
+
- lib/rmtools/enumerable/common.rb
|
|
170
176
|
- lib/rmtools/enumerable/object_space.rb
|
|
171
177
|
- lib/rmtools/enumerable/array_iterators.rb
|
|
172
|
-
- lib/rmtools/
|
|
173
|
-
- lib/rmtools/
|
|
174
|
-
- lib/rmtools/
|
|
175
|
-
- lib/rmtools/
|
|
176
|
-
- lib/rmtools/
|
|
177
|
-
- lib/rmtools
|
|
178
|
-
-
|
|
179
|
-
-
|
|
180
|
-
-
|
|
181
|
-
-
|
|
182
|
-
-
|
|
183
|
-
-
|
|
184
|
-
-
|
|
185
|
-
- ./License.txt
|
|
186
|
-
- ./README.txt
|
|
178
|
+
- lib/rmtools/enumerable/array.rb
|
|
179
|
+
- lib/rmtools/enumerable/hash.rb
|
|
180
|
+
- lib/rmtools/console/coloring.rb
|
|
181
|
+
- lib/rmtools/console/printing.rb
|
|
182
|
+
- lib/rmtools/console/highlight.rb
|
|
183
|
+
- lib/rmtools.rb
|
|
184
|
+
- README.md
|
|
185
|
+
- Manifest.txt
|
|
186
|
+
- ext/rmtools.cpp
|
|
187
|
+
- ext/rmtools.h
|
|
188
|
+
- ext/extconf.rb
|
|
189
|
+
- LICENSE
|
|
190
|
+
- Rakefile
|
|
187
191
|
homepage: https://github.com/tinbka/rmtools
|
|
188
192
|
licenses: []
|
|
189
193
|
post_install_message:
|
|
@@ -206,8 +210,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
206
210
|
version: '0'
|
|
207
211
|
requirements: []
|
|
208
212
|
rubyforge_project: rmtools
|
|
209
|
-
rubygems_version: 1.8.
|
|
213
|
+
rubygems_version: 1.8.23
|
|
210
214
|
signing_key:
|
|
211
215
|
specification_version: 3
|
|
212
|
-
summary:
|
|
216
|
+
summary: ''
|
|
213
217
|
test_files: []
|