tagen 1.1.7 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. data/.gitignore +4 -1
  2. data/.travis.yml +5 -0
  3. data/CHANGELOG +6 -0
  4. data/Gemfile +2 -3
  5. data/Gemfile.lock +13 -15
  6. data/README.md +20 -39
  7. data/Rakefile +2 -1
  8. data/benchmark/a.rb +14 -0
  9. data/lib/tagen/core.rb +17 -22
  10. data/lib/tagen/core/array.rb +5 -109
  11. data/lib/tagen/core/array/append.rb +3 -0
  12. data/lib/tagen/core/array/delete_values.rb +43 -0
  13. data/lib/tagen/core/array/extract_options.rb +35 -94
  14. data/lib/tagen/core/class.rb +1 -0
  15. data/lib/tagen/core/enumerable.rb +15 -18
  16. data/lib/tagen/core/enumerator.rb +22 -12
  17. data/lib/tagen/core/exception.rb +5 -3
  18. data/lib/tagen/core/file.rb +1 -0
  19. data/lib/tagen/core/hash.rb +4 -39
  20. data/lib/tagen/core/integer.rb +2 -0
  21. data/lib/tagen/core/io.rb +59 -26
  22. data/lib/tagen/core/kernel.rb +5 -64
  23. data/lib/tagen/core/kernel/deprecate.rb +5 -0
  24. data/lib/tagen/core/kernel/platform.rb +46 -0
  25. data/lib/tagen/core/kernel/shell.rb +45 -0
  26. data/lib/tagen/core/module.rb +9 -11
  27. data/lib/tagen/core/numeric.rb +4 -2
  28. data/lib/tagen/core/object.rb +6 -21
  29. data/lib/tagen/core/process.rb +6 -4
  30. data/lib/tagen/core/re.rb +2 -2
  31. data/lib/tagen/core/string.rb +12 -47
  32. data/lib/tagen/core/time.rb +30 -38
  33. data/lib/tagen/erb.rb +10 -8
  34. data/lib/tagen/net/http.rb +33 -29
  35. data/lib/tagen/pathname.rb +1 -5
  36. data/lib/tagen/rbconfig.rb +8 -0
  37. data/lib/tagen/socket.rb +8 -2
  38. data/lib/tagen/uri.rb +9 -0
  39. data/lib/tagen/version.rb +1 -1
  40. data/lib/tagen/vim.rb +8 -8
  41. data/lib/tagen/xmpp4r.rb +23 -23
  42. data/spec/spec_helper.rb +23 -17
  43. data/spec/tagen/core/array/delete_values_spec.rb +19 -0
  44. data/spec/tagen/core/array/extract_options_spec.rb +9 -29
  45. data/spec/tagen/core/enumerable_spec.rb +9 -0
  46. data/spec/tagen/core/enumerator_spec.rb +10 -12
  47. data/spec/tagen/core/exception_spec.rb +14 -9
  48. data/spec/tagen/core/io_spec.rb +20 -0
  49. data/spec/tagen/core/kernel/platform_spec.rb +92 -0
  50. data/spec/tagen/core/kernel/shell_spec.rb +27 -0
  51. data/spec/tagen/core/numeric_spec.rb +10 -0
  52. data/spec/tagen/core/process_spec.rb +14 -0
  53. data/spec/tagen/core/re_spec.rb +9 -0
  54. data/spec/tagen/core/string_spec.rb +9 -0
  55. data/spec/tagen/core/time_spec.rb +6 -51
  56. data/spec/tagen/erb_spec.rb +3 -10
  57. data/spec/tagen/pathname_spec.rb +11 -0
  58. data/spec/tagen/rbconfig_spec.rb +11 -0
  59. data/spec/tagen/socket_spec.rb +7 -5
  60. data/spec/tagen/uri_spec.rb +13 -0
  61. data/tagen.gemspec +3 -4
  62. metadata +45 -51
  63. data/TODO +0 -1
  64. data/docs/Architecture.md +0 -17
  65. data/docs/CoreExtensions.md +0 -40
  66. data/docs/ExtraExtensions.md +0 -20
  67. data/lib/tagen/RMagick.rb +0 -12
  68. data/lib/tagen/audioinfo.rb +0 -22
  69. data/lib/tagen/cairo.rb +0 -811
  70. data/lib/tagen/core/extend_hash.rb +0 -46
  71. data/lib/tagen/core/marshal.rb +0 -34
  72. data/lib/tagen/core/open_option.rb +0 -161
  73. data/lib/tagen/core/string/pyformat.rb +0 -336
  74. data/lib/tagen/core/symbol.rb +0 -8
  75. data/lib/tagen/date.rb +0 -80
  76. data/lib/tagen/gdk_pixbuf2.rb +0 -26
  77. data/lib/tagen/gtk2.rb +0 -122
  78. data/lib/tagen/ncurses.rb +0 -246
  79. data/lib/tagen/poppler.rb +0 -48
  80. data/lib/tagen/tree.rb +0 -77
  81. data/lib/tagen/xmpp4r/roster.rb +0 -20
  82. data/lib/tagen/yaml.rb +0 -38
  83. data/spec/tagen/cairo_spec.rb +0 -137
  84. data/spec/tagen/core/array_spec.rb +0 -42
  85. data/spec/tagen/core/extend_hash_spec.rb +0 -54
  86. data/spec/tagen/core/hash_spec.rb +0 -10
  87. data/spec/tagen/core/module_spec.rb +0 -14
  88. data/spec/tagen/core/open_option_spec.rb +0 -83
  89. data/spec/tagen/core/string/pyformat_spec.rb +0 -98
  90. data/spec/tagen/core/symbol_spec.rb +0 -15
  91. data/spec/tagen/core_spec.rb +0 -6
  92. data/spec/tagen/date_spec.rb +0 -146
data/.gitignore CHANGED
@@ -1,3 +1,6 @@
1
+ /tags
2
+
1
3
  /*.gem
4
+ /Gemfile
5
+ /spec/tmp/*
2
6
  /.yardoc
3
- /tags
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - rbx-19mode
5
+ script: bundle exec rspec spec
@@ -0,0 +1,6 @@
1
+ *tagen 2.0.0 (Aug 28, 2012)*
2
+ * based on 'active_support'
3
+ * support 'rubinius' version
4
+
5
+ * remove 'PyFormat', 'Array#extract_extend_options[!]'
6
+ * change 'Time::Detal' to 'Numberic#time_humanize'
data/Gemfile CHANGED
@@ -1,10 +1,9 @@
1
1
  source :rubygems
2
2
 
3
- gem "activesupport", "~>3.1.0"
4
- gem "i18n"
5
3
  gem "pd"
4
+ gem "activesupport", "~>3.2.8"
6
5
 
7
- group :development do
6
+ group :development, :test do
8
7
  gem "rspec"
9
8
  gem "watchr"
10
9
  end
@@ -1,30 +1,28 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activesupport (3.1.3)
4
+ activesupport (3.2.8)
5
+ i18n (~> 0.6)
5
6
  multi_json (~> 1.0)
6
- awesome_print (1.0.2)
7
7
  diff-lcs (1.1.3)
8
8
  i18n (0.6.0)
9
- multi_json (1.0.3)
10
- pd (1.0.3)
11
- rspec (2.7.0)
12
- rspec-core (~> 2.7.0)
13
- rspec-expectations (~> 2.7.0)
14
- rspec-mocks (~> 2.7.0)
15
- rspec-core (2.7.1)
16
- rspec-expectations (2.7.0)
17
- diff-lcs (~> 1.1.2)
18
- rspec-mocks (2.7.0)
9
+ multi_json (1.3.6)
10
+ pd (1.1.0)
11
+ rspec (2.11.0)
12
+ rspec-core (~> 2.11.0)
13
+ rspec-expectations (~> 2.11.0)
14
+ rspec-mocks (~> 2.11.0)
15
+ rspec-core (2.11.1)
16
+ rspec-expectations (2.11.2)
17
+ diff-lcs (~> 1.1.3)
18
+ rspec-mocks (2.11.2)
19
19
  watchr (0.7)
20
20
 
21
21
  PLATFORMS
22
22
  ruby
23
23
 
24
24
  DEPENDENCIES
25
- activesupport (~> 3.1.0)
26
- awesome_print
27
- i18n
25
+ activesupport (~> 3.2.8)
28
26
  pd
29
27
  rspec
30
28
  watchr
data/README.md CHANGED
@@ -1,57 +1,31 @@
1
- Tagen, a core and extra extension to Ruby library.
2
- ==========================================
1
+ # Tagen, a core and extra extension for Ruby [![Build Status](https://secure.travis-ci.org/GutenYe/tagen.png)](http://travis-ci.org/GutenYe/tagen)
3
2
 
4
- | Homepage: | https://github.com/GutenYe/tagen |
3
+ | | |
5
4
  |----------------|-----------------------------------------|
5
+ | Homepage: | https://github.com/GutenYe/tagen |
6
6
  | Author: | Guten |
7
7
  | License: | MIT LICENSE |
8
- | Documentation: | http://rubydoc.info/gems/tagen/frames |
8
+ | Documentation: | https://github.com/GutenYe/tagen/wiki |
9
9
  | Issue Tracker: | https://github.com/GutenYe/tagen/issues |
10
+ | Versions: | Ruby 1.9.3, Rubinius |
10
11
 
11
- Overview
12
- --------
13
-
14
- extensions defined in "active_support" will not appear in here, so you can use it with "active_support".
15
-
16
- Ruby has an 'Open Class' feature, so we can extend any class by ourself.
17
-
18
- This library provides some usefull Ruby core extension. some comes from ActiveSupport. ActiveSupport is mainly target to Rails, but tagen is target to generic ruby development, and tagen is smaller. It is a colletion of most common core,extra extensions.
19
-
20
- This library comes with a string format lib named {PyFormat}.
12
+ It based on "active_support", but it focus on generic ruby programming.
21
13
 
22
14
  Usage
23
15
  -----
24
16
 
25
- use core extension
26
-
27
- require "tagen/core"
28
-
29
- then we have Time.time method, for a list of core extensions, see {file:docs/CoreExtensions.md docs/CoreExtensions}.
30
-
31
- use extra extension
17
+ Cherry-picking a Definition
32
18
 
33
- require "tagen/pathname" # it also require "pathname"
19
+ require "tagen/core/array/delete_values"
34
20
 
35
- this will add #path method to Pathname, see API doc.
21
+ a = [1,2,3]
22
+ a.delete_values(1, 3) -> [1, 3]
23
+ a -> [2]
36
24
 
37
- An Introduction to PyFormat
38
- ---------------------------
25
+ Load All Core Extensions
39
26
 
40
27
  require "tagen/core"
41
- "I like %{fruit} and %{sport}".format('apple', 'football')
42
- "I like %{fruit} and %{sport}".format(fruit: 'apple', sport: 'football')
43
28
 
44
- "it costs %{howmatch:.2f} dollars".format(1.123) #=> "it costs 1.12 dollars"
45
-
46
- more see API doc
47
-
48
-
49
- Documentation
50
- -------------
51
-
52
- * {file:docs/CoreExtensions.md CoreExtensions} A list of core extensions.
53
- * {file:docs/ExtraExtensions.md ExtraExtensions} A list of extra extensions.
54
- * {file:docs/Architecture.md Architecture} Source code architecture.
55
29
 
56
30
  Install
57
31
  ----------
@@ -70,12 +44,19 @@ Contributors
70
44
 
71
45
  * [contributors](https://github.com/GutenYe/tagen/contributors)
72
46
 
47
+ Resources
48
+ ---------
49
+
50
+ * [activesupport](https://github.com/rails/rails/tree/master/activesupport): Utility classes and Ruby extensions from Rails
51
+ * [hashie](https://github.com/intridea/hashie): is a simple collection of useful Hash extensions.
52
+ * [facets](https://github.com/rubyworks/facets): is the premiere collection of general purpose method extensions and standard additions for the Ruby programming language.
53
+
73
54
  Copyright
74
55
  ---------
75
56
 
76
57
  (the MIT License)
77
58
 
78
- Copyright (c) 2011 Guten
59
+ Copyright (c) 2011-2012 Guten
79
60
 
80
61
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
81
62
 
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
- sudo = Process.pid==0 ? "" : "sudo"
1
+ require "rbconfig"
2
+ sudo = Process.pid != 0 && RbConfig::CONFIG["host_os"] !~ /mswin|mingw/ ? "sudo" : ""
2
3
 
3
4
  desc "build a gem file"
4
5
  task :release do
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ dir = File.expand_path("../..", __FILE__)
4
+ $:.unshift File.join(dir, "lib")
5
+ ENV["BUNDLE_GEMFILE"] = File.join(dir, "Gemfile")
6
+
7
+ require "bundler/setup"
8
+ require "benchmark"
9
+
10
+ Benchmark.bm do |b|
11
+ b.report %[require "tagen/core"] do
12
+ require "tagen/core"
13
+ end
14
+ end
@@ -1,26 +1,21 @@
1
1
  require "pd"
2
2
 
3
- # from core
4
- %w(
5
- core/kernel
6
- core/object
7
- core/module
3
+ require "tagen/core/object"
4
+ require "tagen/core/kernel"
5
+ require "tagen/core/module"
6
+ require "tagen/core/class"
8
7
 
9
- core/enumerable
10
- core/enumerator
11
- core/numeric
12
- core/string
13
- core/array
14
- core/hash
15
- core/extend_hash
16
- core/re
8
+ require "tagen/core/numeric"
9
+ require "tagen/core/integer"
10
+ require "tagen/core/string"
11
+ require "tagen/core/enumerable"
12
+ require "tagen/core/enumerator"
13
+ require "tagen/core/array"
14
+ require "tagen/core/hash"
15
+ require "tagen/core/time"
16
+ require "tagen/core/exception"
17
+ require "tagen/core/io"
18
+ require "tagen/core/process"
19
+ require "tagen/core/re"
17
20
 
18
- core/time
19
- core/io
20
- core/process
21
-
22
- core/open_option
23
- ).each {|n| require_relative n }
24
-
25
- # from active_support
26
- require "active_support/core_ext"
21
+ require "active_support/concern"
@@ -1,109 +1,5 @@
1
- require_relative "array/extract_options"
2
- =begin
3
- Additional method list
4
- ----------------------
5
-
6
- * `#append` _alias from push_
7
-
8
- =end
9
- class Array
10
- alias append push
11
-
12
- alias original_delete delete
13
-
14
- # support delete more than one values.
15
- #
16
- # original: delete(v)
17
- # currrent: delete(*v)
18
- #
19
- # @return [Array]
20
- def delete *values, &blk
21
- indexs = values.each.with_object [] do |v,m|
22
- m << original_delete(v, &blk)
23
- end
24
- values.length==1 ? indexs[0] : indexs
25
- end
26
-
27
- alias original_delete_at delete_at
28
-
29
- # support delate_at more than one index.
30
- #
31
- # original: delete_at(i)
32
- # current: delte_at(*i)
33
- #
34
- # @return [Array]
35
- def delete_at *indexs, &blk
36
- values = indexs.each.with_object [] do |i,m|
37
- m << original_delete_at(i, &blk)
38
- end
39
- indexs.length==1 ? values[0] : values
40
- end
41
-
42
-
43
- # first n values, not works at Range, Range don't have #replace method
44
- # @note modify IN PLACE
45
- #
46
- # @example
47
- # a = %w(1 2 3)
48
- # a.first!(2) #=> [1, 2]
49
- # a #=> [3]
50
- # @return Array
51
- def first! n=1
52
- i = 0
53
- j = i + n
54
- k = -1
55
-
56
- ret = self[i...j]
57
- self.replace self[j..k]
58
- ret
59
- end
60
-
61
- # last n values
62
- # @see first!
63
- def last! n=1
64
- i = -1
65
- j = -1 - n + 1
66
- k = 0
67
-
68
- ret = self[j..i]
69
- self.replace self[k...j]
70
- ret
71
- end
72
-
73
- # same as find, but delete the finded value
74
- def find! &blk
75
- idx = self.find_index(&blk)
76
- if idx
77
- self.delete_at(idx)
78
- else
79
- nil
80
- end
81
- end
82
-
83
- # same as find_all, but delete all finded values
84
- def find_all! &blk
85
- ret, rest = [], []
86
- self.each do |k|
87
- if blk.call(k)
88
- ret << k
89
- else
90
- rest << k
91
- end
92
- end
93
- self.replace rest
94
- ret
95
- end
96
-
97
- # confict with gem
98
- #alias original_grep grep
99
-
100
- # confict with awesome_print.
101
- # add grep(arr rb/tage)
102
- #def grep(pat_s, &blk)
103
- #pats = Array===pat_s ? pat_s : [pat_s]
104
- #pats.each.with_object([]) { |k, memo|
105
- #memo.push *self.original_grep(k)
106
- #}
107
- #end
108
-
109
- end # class Array
1
+ require "tagen/core/array/append"
2
+ require "tagen/core/array/delete_values"
3
+ require "tagen/core/array/extract_options"
4
+ require "active_support/core_ext/array/wrap"
5
+ require "active_support/core_ext/array/uniq_by"
@@ -0,0 +1,3 @@
1
+ class Array
2
+ alias append push
3
+ end
@@ -0,0 +1,43 @@
1
+ class Array
2
+ # Deletes items from self.
3
+ #
4
+ # @example
5
+ #
6
+ # a = [1, 2, 3]
7
+ # a.delete_values(1, 3) -> [1, 3]
8
+ # a -> [2]
9
+ #
10
+ # @return [Array]
11
+ # @see Array#delete
12
+ def delete_values(*values, &blk)
13
+ values.each.with_object([]) {|v,m|
14
+ m << delete(v, &blk)
15
+ }
16
+ end
17
+
18
+ # Deletes the element at the specified indexes.
19
+ #
20
+ # @example
21
+ #
22
+ # a = [1, 2, 3]
23
+ # a.delete_values_at(0, 2) -> [1, 3]
24
+ # a -> [2]
25
+ #
26
+ # @return [Array]
27
+ # @see Array#delete_at
28
+ def delete_values_at(*indexs, &blk)
29
+ offset = 0
30
+
31
+ # convert to positve index
32
+ indexs.map { |i| i < 0 ? length + i : i }
33
+
34
+ indexs.each.with_object([]) {|i,m|
35
+ if i > length
36
+ m << nil
37
+ else
38
+ m << delete_at(i-offset, &blk)
39
+ offset += 1
40
+ end
41
+ }
42
+ end
43
+ end
@@ -1,104 +1,45 @@
1
- class Array
2
-
3
- # extend options are symbols and hash, symbol as a boolean option.
4
- #
5
- # :a #=> { a: true }
6
- # :_a #=> { a: false}
7
- #
8
- # @example
9
- # def foo(*args)
10
- # paths, o = args.extract_extend_options
11
- # end
12
- #
13
- # foo(1, :a, :_b, :c => 2)
14
- # #=> paths is [1]
15
- # #=> o is {a: true, b: false, c: 2}
16
- #
17
- # @param [Symbol, Hash] *defaults
18
- # @return [Array<Object>, Hash] \[args, options]
19
- def extract_extend_options *defaults
20
- args, o = _parse_o(defaults)
21
- args1, o1 = _parse_o(self)
22
- [args+args1, o.merge(o1)]
23
- end
1
+ require "active_support/core_ext/array/extract_options"
24
2
 
25
- # modify args IN PLACE.
26
- # @ see extract_extend_options
27
- #
3
+ class Array
4
+ # Extracts options from a set of arguments.
5
+ #
28
6
  # @example
29
- # def foo(*args)
30
- # options = args.extract_extend_options!
31
- # end
32
- #
33
- # foo(1, :a, :_b, c: 2)
34
- # #=> args is [1]
35
- # #=> o is {a: true, b: false, c:2}
36
- #
37
- # @param [Symbol, Hash] *defaults
38
- # @return [Hash] options
39
- def extract_extend_options! *defaults
40
- args, o = extract_extend_options *defaults
41
- self.replace args
42
- o
43
- end
44
-
45
- # @param [Array,Hash] args
46
- def _parse_o args
47
- args = args.dup
48
- # name:1
49
- o1 = Hash === args.last ? args.pop : {}
50
- # :force :_force
51
- rst = args.select{|v| Symbol===v}
52
- args.delete_if{|v| Symbol===v}
53
- o2={}
54
- rst.each do |k|
55
- v = true
56
- if k=~/^_/
57
- k = k[1..-1].to_sym
58
- v = false
59
- end
60
- o2[k] = v
7
+ #
8
+ # dirs, o = ["foo", "bar", {a: 1}].extract_options(b: 2)
9
+ # -> ["foo", "bar"], {a: 1, b: 2}
10
+ #
11
+ # (dir,), o = ["foo", {a: 1}].extract_options
12
+ # -> "foo", {a: 1}
13
+ #
14
+ # @return [Array<Array,Hash>]
15
+ # @see extract_options!
16
+ def extract_options(default={})
17
+ if last.is_a?(Hash) && last.extractable_options?
18
+ [self[0...-1], default.merge(self[-1])]
19
+ else
20
+ [self, default]
61
21
  end
62
- [args, o1.merge(o2)]
63
22
  end
64
- private :_parse_o
65
23
 
66
- # Extracts options from a set of arguments. Removes and returns the last
67
- # element in the array if it's a hash, otherwise returns a blank hash.
68
- # you can also pass a default option.
69
- #
70
- # @example
71
- # def options(*args)
72
- # o = args.extract_options!(:a=>1)
73
- # end
74
- #
75
- # options(1, 2) # => {:a=>1}
76
- # options(1, 2, :a => :b) # => {:a=>:b}
24
+ # Extracts options from a set of arguments. Removes and returns the last
25
+ # element in the array if it's a hash, otherwise returns a blank hash.
26
+ #
27
+ # @example
28
+ #
29
+ # def options(*args)
30
+ # args.extract_options!(a: 1)
31
+ # end
32
+ #
33
+ # options(1, 2) -> {a: 1}
34
+ # options(1, 2, a: 2) -> {a: 2}
77
35
  #
78
36
  # @param [Hash] default default options
79
37
  # @return [Hash]
80
- def extract_options! default={}
81
- if self.last.is_a?(Hash) && self.last.instance_of?(Hash)
82
- self.pop.merge default
83
- else
84
- default
85
- end
38
+ def extract_options!(default={})
39
+ if last.is_a?(Hash) && last.extractable_options?
40
+ default.merge pop
41
+ else
42
+ default
43
+ end
86
44
  end
87
-
88
- # extract options
89
- # @see extract_options!
90
- # @example
91
- # def mkdir(*args)
92
- # paths, o = args.extract_options
93
- # end
94
- #
95
- # @return [Array<Array,Hash>]
96
- def extract_options default={}
97
- if self.last.is_a?(Hash) && self.last.instance_of?(Hash)
98
- [self[0...-1], self[-1].merge(default)]
99
- else
100
- [self, default]
101
- end
102
- end
103
-
104
45
  end