facade 1.0.1 → 1.0.2

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 (7) hide show
  1. data/CHANGES +6 -0
  2. data/MANIFEST +7 -9
  3. data/README +2 -2
  4. data/Rakefile +24 -0
  5. data/lib/facade.rb +21 -7
  6. data/test/tc_facade.rb +20 -10
  7. metadata +8 -3
data/CHANGES CHANGED
@@ -1,3 +1,9 @@
1
+ == 1.0.2 - 11-Jun-2007
2
+ * Added a Rakefile with tasks for installation and testing.
3
+ * Removed the install.rb file. Installation is now handled as a Rake task.
4
+ * Some test suite refactoring.
5
+ * Fixed the FACADE_VERSION number (now 1.0.2, was 1.1.0).
6
+
1
7
  == 1.0.1 - 8-Jun-2005
2
8
  * Moved project to RubyForge.
3
9
  * Added a .gemspec file.
data/MANIFEST CHANGED
@@ -1,9 +1,7 @@
1
- CHANGES
2
- MANIFEST
3
- README
4
- install.rb
5
- facade.gemspec
6
-
7
- lib/facade.rb
8
-
9
- test/tc_facade.rb
1
+ * CHANGES
2
+ * MANIFEST
3
+ * README
4
+ * Rakefile
5
+ * facade.gemspec
6
+ * lib/facade.rb
7
+ * test/tc_facade.rb
data/README CHANGED
@@ -25,7 +25,7 @@
25
25
  shamelessly plagiarized.
26
26
 
27
27
  == Copyright
28
- Copyright (c) 2005 Daniel J. Berger
28
+ Copyright (c) 2005-2007 Daniel J. Berger
29
29
  Licensed under the same terms as Ruby itself.
30
30
 
31
31
  == Warranty
@@ -35,5 +35,5 @@
35
35
 
36
36
  == Author
37
37
  Daniel J. Berger
38
- djberg96 at yahoo dot com
38
+ djberg96 at nospam at gmail dot com
39
39
  imperator on IRC (freenode)
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rbconfig'
4
+ include Config
5
+
6
+ desc 'Install the facade package (non-gem)'
7
+ task :install do
8
+ sitelibdir = CONFIG["sitelibdir"]
9
+ file = "lib/facade.rb"
10
+ FileUtils.cp(file, sitelibdir, :verbose => true)
11
+ end
12
+
13
+ task :install_gem do
14
+ ruby 'facade.gemspec'
15
+ file = Dir["*.gem"].first
16
+ sh "gem install #{file}"
17
+ end
18
+
19
+ Rake::TestTask.new do |t|
20
+ t.libs << 'test'
21
+ t.verbose = true
22
+ t.warning = true
23
+ t.test_files = FileList['test/tc_facade.rb']
24
+ end
data/lib/facade.rb CHANGED
@@ -22,24 +22,38 @@
22
22
  # Licensed under the same terms as Ruby itself.
23
23
 
24
24
  module Facade
25
- FACADE_VERSION = "1.0.1"
25
+ FACADE_VERSION = '1.0.2'
26
26
 
27
- # Forward a class method as an instance method of the including class
27
+ # Forward a class or module method as an instance method of the
28
+ # including class.
28
29
  #
29
30
  # call-seq:
30
- # forward +Klass+, :method
31
- # forward +Klass+, :method1, :method2, ...
31
+ # forward +klass+, :method
32
+ # forward +klass+, :method1, :method2, ...
32
33
  #
33
34
  # This will not override the class' existing methods.
35
+ #
34
36
  def facade(klass, *methods)
35
37
  methods.flatten!
36
- methods = klass.methods(false) if methods.empty? # Default to all methods
37
- methods.collect!{|m| m.to_s} # Symbols or strings
38
+ if methods.empty? # Default to all methods
39
+ if klass.kind_of?(Class)
40
+ methods = klass.methods(false)
41
+ else
42
+ methods = klass.public_instance_methods(false)
43
+ end
44
+ end
45
+ methods.collect!{ |m| m.to_s } # Symbols or strings
38
46
  methods -= self.instance_methods # No clobber
39
47
 
40
48
  methods.each do |methname|
49
+ methname = methname.to_sym
41
50
  define_method(methname){ ||
42
- meth = klass.method(methname)
51
+ if klass.kind_of?(Class)
52
+ meth = klass.method(methname)
53
+ else
54
+ meth = Object.new.extend(klass).method(methname)
55
+ end
56
+
43
57
  if meth.arity.zero? # Zero or one argument
44
58
  meth.call
45
59
  else
data/test/tc_facade.rb CHANGED
@@ -1,22 +1,23 @@
1
- #####################################
1
+ #########################################################################
2
2
  # tc_facade.rb
3
3
  #
4
- # Test suite for the Facade module.
5
- #####################################
6
- base = File.basename(Dir.pwd)
7
- if base == "test" || base =~ /facade.*/
8
- Dir.chdir("..") if base == "test"
9
- $LOAD_PATH.unshift(Dir.pwd)
10
- $LOAD_PATH.unshift(Dir.pwd + "/lib")
11
- end
12
-
4
+ # Test suite for the Facade module. This test suite should be run via
5
+ # the 'rake test' task.
6
+ #########################################################################
13
7
  require "test/unit"
14
8
  require "facade"
15
9
 
10
+ module Baz
11
+ def testme(str)
12
+ str
13
+ end
14
+ end
15
+
16
16
  class Foo < String
17
17
  extend Facade
18
18
  facade File, :basename, "dirname"
19
19
  facade Dir
20
+ facade Baz
20
21
  def blockdev?
21
22
  "test"
22
23
  end
@@ -26,6 +27,10 @@ class TC_Facade < Test::Unit::TestCase
26
27
  def setup
27
28
  @f = Foo.new("/home/djberge")
28
29
  end
30
+
31
+ def test_facade_version
32
+ assert_equal('1.0.2', Facade::FACADE_VERSION)
33
+ end
29
34
 
30
35
  def test_file_methods
31
36
  assert_respond_to(@f, :basename)
@@ -49,6 +54,11 @@ class TC_Facade < Test::Unit::TestCase
49
54
  assert_equal("test", @f.blockdev?)
50
55
  end
51
56
 
57
+ def test_module_methods
58
+ assert_respond_to(@f, :testme)
59
+ assert_equal("/home/djberge", @f.testme)
60
+ end
61
+
52
62
  def teardown
53
63
  @f = nil
54
64
  end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.10
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: facade
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.1
7
- date: 2005-06-09
6
+ version: 1.0.2
7
+ date: 2007-06-11 00:00:00 -06:00
8
8
  summary: An easy way to implement the facade pattern in your class
9
9
  require_paths:
10
10
  - lib
@@ -23,12 +23,16 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
23
23
  version: 0.0.0
24
24
  version:
25
25
  platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
26
29
  authors:
27
30
  - Daniel J. Berger
28
31
  files:
29
32
  - lib/facade.rb
30
33
  - CHANGES
31
34
  - MANIFEST
35
+ - Rakefile
32
36
  - README
33
37
  - test/tc_facade.rb
34
38
  test_files:
@@ -38,6 +42,7 @@ rdoc_options: []
38
42
  extra_rdoc_files:
39
43
  - README
40
44
  - CHANGES
45
+ - MANIFEST
41
46
  executables: []
42
47
 
43
48
  extensions: []