tagen 1.1.7 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -1
- data/.travis.yml +5 -0
- data/CHANGELOG +6 -0
- data/Gemfile +2 -3
- data/Gemfile.lock +13 -15
- data/README.md +20 -39
- data/Rakefile +2 -1
- data/benchmark/a.rb +14 -0
- data/lib/tagen/core.rb +17 -22
- data/lib/tagen/core/array.rb +5 -109
- data/lib/tagen/core/array/append.rb +3 -0
- data/lib/tagen/core/array/delete_values.rb +43 -0
- data/lib/tagen/core/array/extract_options.rb +35 -94
- data/lib/tagen/core/class.rb +1 -0
- data/lib/tagen/core/enumerable.rb +15 -18
- data/lib/tagen/core/enumerator.rb +22 -12
- data/lib/tagen/core/exception.rb +5 -3
- data/lib/tagen/core/file.rb +1 -0
- data/lib/tagen/core/hash.rb +4 -39
- data/lib/tagen/core/integer.rb +2 -0
- data/lib/tagen/core/io.rb +59 -26
- data/lib/tagen/core/kernel.rb +5 -64
- data/lib/tagen/core/kernel/deprecate.rb +5 -0
- data/lib/tagen/core/kernel/platform.rb +46 -0
- data/lib/tagen/core/kernel/shell.rb +45 -0
- data/lib/tagen/core/module.rb +9 -11
- data/lib/tagen/core/numeric.rb +4 -2
- data/lib/tagen/core/object.rb +6 -21
- data/lib/tagen/core/process.rb +6 -4
- data/lib/tagen/core/re.rb +2 -2
- data/lib/tagen/core/string.rb +12 -47
- data/lib/tagen/core/time.rb +30 -38
- data/lib/tagen/erb.rb +10 -8
- data/lib/tagen/net/http.rb +33 -29
- data/lib/tagen/pathname.rb +1 -5
- data/lib/tagen/rbconfig.rb +8 -0
- data/lib/tagen/socket.rb +8 -2
- data/lib/tagen/uri.rb +9 -0
- data/lib/tagen/version.rb +1 -1
- data/lib/tagen/vim.rb +8 -8
- data/lib/tagen/xmpp4r.rb +23 -23
- data/spec/spec_helper.rb +23 -17
- data/spec/tagen/core/array/delete_values_spec.rb +19 -0
- data/spec/tagen/core/array/extract_options_spec.rb +9 -29
- data/spec/tagen/core/enumerable_spec.rb +9 -0
- data/spec/tagen/core/enumerator_spec.rb +10 -12
- data/spec/tagen/core/exception_spec.rb +14 -9
- data/spec/tagen/core/io_spec.rb +20 -0
- data/spec/tagen/core/kernel/platform_spec.rb +92 -0
- data/spec/tagen/core/kernel/shell_spec.rb +27 -0
- data/spec/tagen/core/numeric_spec.rb +10 -0
- data/spec/tagen/core/process_spec.rb +14 -0
- data/spec/tagen/core/re_spec.rb +9 -0
- data/spec/tagen/core/string_spec.rb +9 -0
- data/spec/tagen/core/time_spec.rb +6 -51
- data/spec/tagen/erb_spec.rb +3 -10
- data/spec/tagen/pathname_spec.rb +11 -0
- data/spec/tagen/rbconfig_spec.rb +11 -0
- data/spec/tagen/socket_spec.rb +7 -5
- data/spec/tagen/uri_spec.rb +13 -0
- data/tagen.gemspec +3 -4
- metadata +45 -51
- data/TODO +0 -1
- data/docs/Architecture.md +0 -17
- data/docs/CoreExtensions.md +0 -40
- data/docs/ExtraExtensions.md +0 -20
- data/lib/tagen/RMagick.rb +0 -12
- data/lib/tagen/audioinfo.rb +0 -22
- data/lib/tagen/cairo.rb +0 -811
- data/lib/tagen/core/extend_hash.rb +0 -46
- data/lib/tagen/core/marshal.rb +0 -34
- data/lib/tagen/core/open_option.rb +0 -161
- data/lib/tagen/core/string/pyformat.rb +0 -336
- data/lib/tagen/core/symbol.rb +0 -8
- data/lib/tagen/date.rb +0 -80
- data/lib/tagen/gdk_pixbuf2.rb +0 -26
- data/lib/tagen/gtk2.rb +0 -122
- data/lib/tagen/ncurses.rb +0 -246
- data/lib/tagen/poppler.rb +0 -48
- data/lib/tagen/tree.rb +0 -77
- data/lib/tagen/xmpp4r/roster.rb +0 -20
- data/lib/tagen/yaml.rb +0 -38
- data/spec/tagen/cairo_spec.rb +0 -137
- data/spec/tagen/core/array_spec.rb +0 -42
- data/spec/tagen/core/extend_hash_spec.rb +0 -54
- data/spec/tagen/core/hash_spec.rb +0 -10
- data/spec/tagen/core/module_spec.rb +0 -14
- data/spec/tagen/core/open_option_spec.rb +0 -83
- data/spec/tagen/core/string/pyformat_spec.rb +0 -98
- data/spec/tagen/core/symbol_spec.rb +0 -15
- data/spec/tagen/core_spec.rb +0 -6
- data/spec/tagen/date_spec.rb +0 -146
data/lib/tagen/core/object.rb
CHANGED
@@ -1,21 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
# a2 = a.dup
|
8
|
-
# a2[:a][:b] = 2
|
9
|
-
# p a #=> {a: {b: 2} }
|
10
|
-
#
|
11
|
-
# # use deepdup
|
12
|
-
# a= {a: {b: 1 }}
|
13
|
-
# a2 = a.deepdup
|
14
|
-
# a2[:a][:b] = 2
|
15
|
-
# p a #=> {a: {b: 1}}
|
16
|
-
#
|
17
|
-
# @return [Object]
|
18
|
-
def deepdup
|
19
|
-
Marshal.load(Marshal.dump(self))
|
20
|
-
end
|
21
|
-
end
|
1
|
+
require "active_support/core_ext/object/blank"
|
2
|
+
require "active_support/core_ext/object/inclusion"
|
3
|
+
require "active_support/core_ext/object/try"
|
4
|
+
#require "active_support/core_ext/object/deep_dup"
|
5
|
+
require "active_support/core_ext/object/instance_variables"
|
6
|
+
require "active_support/core_ext/object/duplicable"
|
data/lib/tagen/core/process.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
require "tagen/core/kernel/platform"
|
2
|
+
|
1
3
|
module Process
|
2
|
-
#
|
3
|
-
#
|
4
|
+
# Check if the pid's process is running.
|
4
5
|
# @note for linux only
|
5
|
-
#
|
6
|
+
#
|
7
|
+
# @param [Integer] pid process id
|
6
8
|
# @return [Boolean]
|
7
9
|
def self.exists?(pid)
|
8
|
-
raise
|
10
|
+
raise NotImplementedError unless linux?
|
9
11
|
File.exists?("/proc/#{pid}")
|
10
12
|
end
|
11
13
|
end
|
data/lib/tagen/core/re.rb
CHANGED
data/lib/tagen/core/string.rb
CHANGED
@@ -1,48 +1,13 @@
|
|
1
|
-
class String
|
2
|
-
|
3
|
-
|
4
|
-
@@octdigits = "01234567"
|
5
|
-
@@uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
6
|
-
@@lowercase = "abcdefghijklmnopqrstuvwxyz"
|
7
|
-
@@letters = @@uppercase + @@lowercase
|
8
|
-
|
9
|
-
class << self
|
10
|
-
|
11
|
-
# "0123456789"
|
12
|
-
#
|
13
|
-
# @return [String]
|
14
|
-
def digits; @@digits end
|
15
|
-
|
16
|
-
# "01234567890ABCDEF"
|
17
|
-
#
|
18
|
-
# @return [String]
|
19
|
-
def hexdigits; @@hexdigits end
|
20
|
-
|
21
|
-
# "01234567"
|
22
|
-
#
|
23
|
-
# @return [String]
|
24
|
-
def octdigits; @@octdigits end
|
25
|
-
|
26
|
-
# "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
27
|
-
#
|
28
|
-
# @return [String]
|
29
|
-
def uppercase; @@uppercase end
|
30
|
-
|
31
|
-
# "abcdefghijklmnopqrstuvwxyz"
|
32
|
-
#
|
33
|
-
# @return [String]
|
34
|
-
def lowercase; @@lowercase end
|
35
|
-
|
36
|
-
# "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
37
|
-
#
|
38
|
-
# @return [String]
|
39
|
-
def letters; @@letters end
|
40
|
-
end
|
41
|
-
|
42
|
-
# return ascii code
|
1
|
+
class String
|
2
|
+
# Return first character's ascii code.
|
3
|
+
#
|
43
4
|
# @example
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
5
|
+
#
|
6
|
+
# 'a'.ascii -> 97
|
7
|
+
#
|
8
|
+
def ascii()
|
9
|
+
bytes.first
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
require "active_support/core_ext/string"
|
data/lib/tagen/core/time.rb
CHANGED
@@ -1,50 +1,42 @@
|
|
1
1
|
class Time
|
2
|
-
#
|
2
|
+
# Return a float of time since linux epoch
|
3
3
|
#
|
4
|
-
|
4
|
+
# @example
|
5
|
+
#
|
6
|
+
# Time.time -> 1295953427.0005338
|
5
7
|
#
|
6
8
|
# @return [Float]
|
7
9
|
def self.time
|
8
10
|
now.to_f
|
9
11
|
end
|
12
|
+
end
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
deta, @seconds = deta.divmod(60)
|
27
|
-
deta, @minutes = deta.divmod(60)
|
28
|
-
deta, @hours = deta.divmod(24)
|
29
|
-
deta, @days = deta.divmod(30)
|
30
|
-
@years, @months = deta.divmod(12)
|
31
|
-
end
|
32
|
-
|
33
|
-
def display(include_seconds=true)
|
34
|
-
ret = ""
|
35
|
-
ret << "#{years} years " unless years == 0
|
36
|
-
ret << "#{months} months " unless months == 0
|
37
|
-
ret << "#{days} days " unless days==0
|
38
|
-
ret << "#{hours} hours " unless hours == 0
|
39
|
-
ret << "#{minutes} minutes " unless minutes == 0
|
40
|
-
ret << "#{seconds} seconds" if include_seconds
|
14
|
+
class Numeric
|
15
|
+
# Reports the approximate distance in time between two Time, Date or DateTime objects or integers as seconds.
|
16
|
+
#
|
17
|
+
# @example
|
18
|
+
#
|
19
|
+
# 1.time_humanize(true) -> 1 seconds
|
20
|
+
# 36561906.time_humanize -> 1 years 2 months 3 days 4 hours 5 minutes
|
21
|
+
#
|
22
|
+
def time_humanize(include_seconds=false)
|
23
|
+
deta = self
|
24
|
+
deta, seconds = deta.divmod(60)
|
25
|
+
deta, minutes = deta.divmod(60)
|
26
|
+
deta, hours = deta.divmod(24)
|
27
|
+
deta, days = deta.divmod(30)
|
28
|
+
years, months = deta.divmod(12)
|
41
29
|
|
42
|
-
|
43
|
-
|
30
|
+
ret = ""
|
31
|
+
ret << "#{years} years " unless years == 0
|
32
|
+
ret << "#{months} months " unless months == 0
|
33
|
+
ret << "#{days} days " unless days == 0
|
34
|
+
ret << "#{hours} hours " unless hours == 0
|
35
|
+
ret << "#{minutes} minutes " unless minutes == 0
|
36
|
+
ret << "#{seconds} seconds" if include_seconds
|
44
37
|
|
45
|
-
|
46
|
-
def to_a
|
47
|
-
[ years, months, days, hours, minutes, seconds ]
|
48
|
-
end
|
38
|
+
ret.rstrip
|
49
39
|
end
|
50
40
|
end
|
41
|
+
|
42
|
+
require "active_support/time"
|
data/lib/tagen/erb.rb
CHANGED
@@ -1,25 +1,28 @@
|
|
1
|
-
require
|
1
|
+
require "erb"
|
2
2
|
|
3
3
|
class ERB
|
4
|
-
alias original_result result
|
5
|
-
|
6
4
|
# add locals support
|
5
|
+
#
|
6
|
+
# @param [Hash,OpenOption] locals
|
7
7
|
#
|
8
8
|
# @example
|
9
|
+
#
|
9
10
|
# erb = Erb.new("<%=a%>")
|
10
11
|
# erb.result(nil, a: 1) #=> "1"
|
11
12
|
#
|
12
|
-
|
13
|
-
def result(bind=nil, locals={})
|
13
|
+
def result_with_tagen(bind=nil, locals={})
|
14
14
|
bind ||= TOPLEVEL_BINDING
|
15
15
|
if locals.empty?
|
16
|
-
|
16
|
+
result_without_tagen bind
|
17
17
|
else
|
18
18
|
result_with_locals bind, locals
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
|
22
|
+
alias result_without_tagen result
|
23
|
+
alias result result_with_tagen
|
24
|
+
|
25
|
+
private
|
23
26
|
def result_with_locals(bind, locals)
|
24
27
|
@locals = locals
|
25
28
|
evalstr = <<-EOF
|
@@ -32,5 +35,4 @@ end
|
|
32
35
|
eval evalstr
|
33
36
|
run_erb
|
34
37
|
end
|
35
|
-
|
36
38
|
end
|
data/lib/tagen/net/http.rb
CHANGED
@@ -1,34 +1,38 @@
|
|
1
|
+
require "net/http"
|
2
|
+
|
1
3
|
module Net
|
2
|
-
class HTTP
|
3
|
-
|
4
|
+
class HTTP
|
5
|
+
class << self
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
7
|
+
# support params
|
8
|
+
#
|
9
|
+
# @param [String Hash] params Hash by URI.encoding_www_form
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
#
|
13
|
+
# get1("http://www.google.com/search", "&q=foo")
|
14
|
+
# get1("http://www.google.com/search", {"q" => "foo"} )
|
15
|
+
#
|
16
|
+
def get1 path, params, initheader={}, &blk
|
17
|
+
path = path + "?" + (String===params ? params : URI.encode_www_form(params))
|
18
|
+
req = Get.new(path, initheader)
|
19
|
+
request req, &blk
|
20
|
+
end
|
17
21
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
22
|
+
# support params
|
23
|
+
#
|
24
|
+
# @see get1
|
25
|
+
def post1 path, params, initheader={}, &blk
|
26
|
+
req = Post.new(path, initheader)
|
27
|
+
if String===params
|
28
|
+
req.body = params
|
29
|
+
req.content_type = 'application/x-www-form-urlencoded'
|
30
|
+
else
|
31
|
+
req.set_form_data(params)
|
32
|
+
end
|
33
|
+
request req, &blk
|
34
|
+
end
|
31
35
|
|
32
|
-
|
33
|
-
end
|
36
|
+
end
|
37
|
+
end
|
34
38
|
end
|
data/lib/tagen/pathname.rb
CHANGED
data/lib/tagen/socket.rb
CHANGED
@@ -63,18 +63,24 @@ class Socket
|
|
63
63
|
# pack human-readable address to Socket address
|
64
64
|
#
|
65
65
|
# @example
|
66
|
+
#
|
66
67
|
# addr("192.168.1.1") #=> "\xC0\xA8\x01\x01"
|
67
68
|
#
|
68
69
|
# @return [String] address used by Socket
|
69
70
|
# @see unaddr
|
70
|
-
def addr(str)
|
71
|
+
def addr(str)
|
72
|
+
str.split(".").map{|v|v.to_i}.pack("CCCC")
|
73
|
+
end
|
71
74
|
|
72
75
|
# unpack to humna-readable address from Socket address
|
73
76
|
#
|
74
77
|
# @example
|
78
|
+
#
|
75
79
|
# unaddr("\xC0\xA8\x01\x01") #=> "192.168.1.1"
|
76
80
|
#
|
77
81
|
# @return [String] human readable address
|
78
|
-
def unaddr(str)
|
82
|
+
def unaddr(str)
|
83
|
+
str.unpack("CCCC").join(".")
|
84
|
+
end
|
79
85
|
end
|
80
86
|
end
|
data/lib/tagen/uri.rb
ADDED
data/lib/tagen/version.rb
CHANGED
data/lib/tagen/vim.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
=end
|
1
|
+
# used by VimL(Vim Script)
|
2
|
+
#
|
4
3
|
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
|
4
|
+
# @example
|
5
|
+
#
|
6
|
+
# vimprint "guten" -> guten\n
|
7
|
+
# vimprint "guten\ntag" -> guten\n
|
8
|
+
#
|
9
|
+
def vimprint(*args)
|
10
10
|
args.each do |arg|
|
11
11
|
arg = arg.to_s
|
12
12
|
arg.split("\n").each {|v| print v}
|
data/lib/tagen/xmpp4r.rb
CHANGED
@@ -1,35 +1,35 @@
|
|
1
1
|
require "xmpp4r"
|
2
|
-
require "tagen/xmpp4r/roster"
|
3
2
|
|
4
|
-
#
|
3
|
+
# bugfix. support UTF-8
|
4
|
+
# patch from https://github.com/ln/xmpp4r/issues/3#issuecomment-1739952
|
5
5
|
|
6
6
|
if RUBY_VERSION < "1.9"
|
7
7
|
# ...
|
8
8
|
else
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
9
|
+
# Encoding patch
|
10
|
+
require 'socket'
|
11
|
+
class TCPSocket
|
12
|
+
def external_encoding
|
13
|
+
Encoding::BINARY
|
15
14
|
end
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
17
|
+
require 'rexml/source'
|
18
|
+
class REXML::IOSource
|
19
|
+
alias_method :encoding_assign, :encoding=
|
20
|
+
def encoding=(value)
|
21
|
+
encoding_assign(value) if value
|
23
22
|
end
|
23
|
+
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
33
|
-
rescue
|
25
|
+
begin
|
26
|
+
# OpenSSL is optional and can be missing
|
27
|
+
require 'openssl'
|
28
|
+
class OpenSSL::SSL::SSLSocket
|
29
|
+
def external_encoding
|
30
|
+
Encoding::BINARY
|
31
|
+
end
|
34
32
|
end
|
33
|
+
rescue
|
34
|
+
end
|
35
35
|
end
|