facets 2.8.2 → 2.8.3

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.
Files changed (57) hide show
  1. data/AUTHORS +13 -11
  2. data/HISTORY.rdoc +58 -0
  3. data/lib/core/facets/array/recursive.rb +91 -0
  4. data/lib/core/facets/array/recursively.rb +2 -2
  5. data/lib/core/facets/array/traverse.rb +23 -6
  6. data/lib/core/facets/enumerable/collisions.rb +1 -0
  7. data/lib/core/facets/enumerable/commonality.rb +4 -2
  8. data/lib/core/facets/enumerable/graph.rb +37 -1
  9. data/lib/core/facets/enumerable/mash.rb +1 -39
  10. data/lib/core/facets/enumerable/recursive.rb +75 -0
  11. data/lib/core/facets/enumerable/visit.rb +30 -0
  12. data/lib/core/facets/file/ext.rb +36 -0
  13. data/lib/core/facets/hash/graph.rb +18 -0
  14. data/lib/core/facets/hash/mash.rb +1 -18
  15. data/lib/core/facets/hash/recursive.rb +180 -0
  16. data/lib/core/facets/hash/recursive_merge.rb +6 -0
  17. data/lib/core/facets/hash/recursively.rb +2 -2
  18. data/lib/core/facets/hash/to_module.rb +26 -0
  19. data/lib/core/facets/hash/to_proc.rb +2 -2
  20. data/lib/core/facets/hash/traverse.rb +19 -13
  21. data/lib/core/facets/kernel/assign.rb +63 -0
  22. data/lib/core/facets/kernel/assign_from.rb +45 -0
  23. data/lib/core/facets/kernel/dup.rb +63 -0
  24. data/lib/core/facets/kernel/instance.rb +156 -0
  25. data/lib/core/facets/kernel/instance_assign.rb +1 -22
  26. data/lib/core/facets/kernel/meta_def.rb +4 -0
  27. data/lib/core/facets/kernel/populate.rb +1 -74
  28. data/lib/core/facets/kernel/set_from.rb +2 -0
  29. data/lib/core/facets/kernel/try_dup.rb +1 -0
  30. data/lib/core/facets/module/set.rb +36 -0
  31. data/lib/core/facets/objectspace/reflect.rb +45 -0
  32. data/lib/core/facets/struct/attributes.rb +6 -2
  33. data/lib/core/facets/symbol/op_div.rb +19 -0
  34. data/lib/core/facets/to_hash.rb +12 -0
  35. data/lib/more/facets/casting_hash.rb +172 -0
  36. data/lib/more/facets/pathname.rb +36 -0
  37. data/lib/more/facets/prepend.rb +57 -0
  38. data/lib/more/facets/random.rb +19 -3
  39. data/lib/more/facets/roman.rb +46 -153
  40. data/lib/more/facets/stash.rb +148 -33
  41. data/meta/released +1 -1
  42. data/meta/version +1 -1
  43. data/test/core/array/test_recursive.rb +18 -0
  44. data/test/core/enumerable/test_recursive.rb +18 -0
  45. data/test/core/file/test_ext.rb +31 -0
  46. data/test/core/hash/test_recursive.rb +23 -0
  47. data/test/core/hash/test_to_module.rb +21 -0
  48. data/test/core/kernel/test_assign.rb +57 -0
  49. data/test/core/kernel/test_assign_from.rb +20 -0
  50. data/test/more/test_prepend.rb +28 -0
  51. data/test/more/test_random.rb +40 -4
  52. metadata +39 -10
  53. data/lib/core/facets/kernel/instance_variables.rb +0 -97
  54. data/lib/more/facets/instance_eval.rb +0 -50
  55. data/lib/more/facets/ioredirect.rb +0 -77
  56. data/lib/more/facets/plugin_manager.rb +0 -50
  57. data/test/core/kernel/test_populate.rb +0 -46
@@ -1,77 +0,0 @@
1
- warn "IORedirect is being deprecated. It is not a robust solution. If you use this library, please consider contributing to Facets by rewritting the library so we can keep it in Facets."
2
-
3
- # = IORedirect
4
- #
5
- # IORedirect was ported from Paul Brannan's Ruby Treasures.
6
- #
7
- # Copyright (C) 2002 Paul Brannan <paul@atdesk.com>
8
- #
9
- # Ruby License
10
- #
11
- # This module is free software. You may use, modify, and/or redistribute this
12
- # software under the same terms as Ruby.
13
- #
14
- # This program is distributed in the hope that it will be useful, but WITHOUT
15
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16
- # FOR A PARTICULAR PURPOSE.
17
-
18
- require 'thread'
19
-
20
- # = IORedirect
21
- #
22
- # A class to redirect $stdout, or other IO object, to a StringIO object,
23
- # or any other object with a write() method.
24
- #
25
- # s = StringIO.new
26
- # r = IORedirect.redirect($stdout, s) do
27
- # $stdout.puts "this is a test"
28
- # end
29
- #
30
- class IORedirect
31
-
32
- # Start redirection from one IO object to any other object with a
33
- # write() method. +from+ is the IO object to redirect from,
34
- # and +to+ is the object to redirect to.
35
- def initialize(from, to)
36
- @from = from
37
- @to = to
38
- start()
39
- end
40
-
41
- # Start redirection, if it has not already been started.
42
- def start
43
- raise "Redirection already in progress" if @t
44
- tmp = @from.dup
45
- r, w = *IO.pipe
46
- @from.reopen(w)
47
- @t = Thread.new do
48
- begin
49
- loop do
50
- s = r.read(1) # TODO: can I make this buffered?
51
- @to.write(s)
52
- end
53
- ensure
54
- @from.reopen(tmp)
55
- @t = nil
56
- end
57
- end
58
- end
59
-
60
- # Stop redirection, if it is occurring
61
- def stop
62
- raise "Redirection already stopped" if not @t
63
- @t.kill
64
- end
65
-
66
- # An exception-safe class method for redirection
67
- def self.redirect(from, to)
68
- s = new(from, to)
69
- begin
70
- yield
71
- ensure
72
- s.stop
73
- end
74
- end
75
-
76
- end
77
-
@@ -1,50 +0,0 @@
1
- # = Plugin Manger
2
- #
3
- # Find plugins easily.
4
- #
5
- # NOTE: This is likely to be replaced with
6
- # a more generic means of finding libraries.
7
- #
8
- module PluginManager
9
- extend self
10
-
11
- # Find plugins, searching through standard $LOAD_PATH,
12
- # Roll Libraries and RubyGems.
13
- #
14
- # +match+ is a file glob for finding plugins.
15
- #
16
- # PluginManager.find('syckles/*')
17
- #
18
- def find(match)
19
- plugins = []
20
- # Standard $LOAD_PATH
21
- $LOAD_PATH.uniq.each do |path|
22
- list = Dir.glob(File.join(path, match))
23
- #dirs = dirs.select{ |d| File.directory?(d) }
24
- list = list.map{ |d| d.chomp('/') }
25
- plugins.concat(list)
26
- end
27
- # ROLL (load latest versions only)
28
- if defined?(::Roll)
29
- ::Roll::Library.ledger.each do |name, lib|
30
- lib = lib.sort.first if Array===lib
31
- lib.load_path.each do |path|
32
- find = File.join(lib.location, path, match)
33
- list = Dir.glob(find)
34
- list = list.map{ |d| d.chomp('/') }
35
- plugins.concat(list)
36
- end
37
- end
38
- end
39
- # RubyGems (load latest versions only)
40
- if defined?(::Gem)
41
- Gem.latest_load_paths do |path|
42
- list = Dir.glob(File.join(path, match))
43
- list = list.map{ |d| d.chomp('/') }
44
- plugins.concat(list)
45
- end
46
- end
47
- plugins
48
- end
49
-
50
- end
@@ -1,46 +0,0 @@
1
- require 'facets/kernel/populate.rb'
2
- require 'test/unit'
3
-
4
- class TestKernelPopulate < Test::Unit::TestCase
5
-
6
- Customer = Struct.new( "Customer", :name, :address, :zip )
7
-
8
- # def test_assign_from
9
- # o = Object.new
10
- # o.instance_eval{ @z=0; @a=1; @b=2 } #; @@a=3 }
11
- # assign_from( o, "z", "@a", "@b" ) #, "@@a" )
12
- # assert_equal( 1, @a )
13
- # assert_equal( 2, @b )
14
- # #assert_equal( 3, @@a )
15
- # end
16
-
17
- def test_set_from
18
- bob = Customer.new("Bob Sawyer", "123 Maple, Anytown NC", 12345)
19
- joe = Customer.new("Joe Pitare")
20
- joe.set_from(bob, :address, :zip)
21
- assert_equal("Joe Pitare", joe.name)
22
- assert_equal("123 Maple, Anytown NC", joe.address)
23
- assert_equal(12345, joe.zip)
24
- end
25
-
26
- #Customer = Struct.new( "Customer", :name, :address, :zip )
27
-
28
- def test_populate_with_hash
29
- bob = Customer.new()
30
- x = { :name => "Bob Sawyer", :address => "123 Maple, Anytown NC", :zip => 12345 }
31
- bob.populate(x)
32
- assert_equal(x[:name], bob.name)
33
- assert_equal(x[:address], bob.address)
34
- assert_equal(x[:zip], bob.zip)
35
- end
36
-
37
- def test_populate_with_block
38
- bob = Customer.new()
39
- x = lambda {|s| s.name = "Bob Sawyer"; s.address = "123 Maple, Anytown NC"; s.zip = 12345 }
40
- bob.populate(&x)
41
- assert_equal("Bob Sawyer", bob.name)
42
- assert_equal("123 Maple, Anytown NC", bob.address)
43
- assert_equal(12345, bob.zip)
44
- end
45
-
46
- end