facade 1.0.2 → 1.0.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.
data/CHANGES CHANGED
@@ -1,13 +1,20 @@
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
-
7
- == 1.0.1 - 8-Jun-2005
8
- * Moved project to RubyForge.
9
- * Added a .gemspec file.
10
- * Added a MANIFEST.
11
-
12
- == 1.0.0 - 18-May-2005
13
- * Initial release
1
+ == 1.0.3 - 21-Jul-2009
2
+ * License changed to Artistic 2.0.
3
+ * Documentation updates.
4
+ * Test file renamed to test_facade.rb.
5
+ * Some Rakefile and gemspec updates
6
+ * One test modified so that it passes with 1.9.x as well.
7
+
8
+ == 1.0.2 - 11-Jun-2007
9
+ * Added a Rakefile with tasks for installation and testing.
10
+ * Removed the install.rb file. Installation is now handled as a Rake task.
11
+ * Some test suite refactoring.
12
+ * Fixed the FACADE_VERSION number (now 1.0.2, was 1.1.0).
13
+
14
+ == 1.0.1 - 8-Jun-2005
15
+ * Moved project to RubyForge.
16
+ * Added a .gemspec file.
17
+ * Added a MANIFEST.
18
+
19
+ == 1.0.0 - 18-May-2005
20
+ * Initial release
data/MANIFEST CHANGED
@@ -4,4 +4,4 @@
4
4
  * Rakefile
5
5
  * facade.gemspec
6
6
  * lib/facade.rb
7
- * test/tc_facade.rb
7
+ * test/test_facade.rb
data/README CHANGED
@@ -1,22 +1,23 @@
1
1
  == Synopsis
2
- An easy way to implement the facade pattern in your classes.
2
+ An easy way to implement the facade pattern in your classes. In short,
3
+ this library wraps singleton methods from another class as instance
4
+ methods of the current class.
3
5
 
4
6
  == Prerequisites
5
7
  Ruby 1.8.0 or later
6
8
 
7
9
  == Installation
8
- ruby test/tc_facade.rb (optional)
9
- ruby install.rb
10
+ rake test
11
+ rake install (non-gem) or rake install_gem (gem)
10
12
 
11
13
  == Usage
12
- require "facade"
13
- class Foo < String
14
+ require 'facade'
15
+ class MyString < String
14
16
  extend Facade
15
17
  facade File, :dirname, :basename
16
- facade Dir
17
18
  end
18
19
 
19
- f = Foo.new("/home/djberge")
20
+ f = MyString.new('/home/djberge')
20
21
  puts f.basename # 'djberge'
21
22
  puts f.dirname # '/home'
22
23
 
@@ -25,8 +26,11 @@
25
26
  shamelessly plagiarized.
26
27
 
27
28
  == Copyright
28
- Copyright (c) 2005-2007 Daniel J. Berger
29
- Licensed under the same terms as Ruby itself.
29
+ Copyright (c) 2005-2009 Daniel J. Berger
30
+ Licensed under the same terms as Ruby itself.
31
+
32
+ == License
33
+ Artistic 2.0
30
34
 
31
35
  == Warranty
32
36
  This package is provided "as is" and without any express or
@@ -36,4 +40,4 @@
36
40
  == Author
37
41
  Daniel J. Berger
38
42
  djberg96 at nospam at gmail dot com
39
- imperator on IRC (freenode)
43
+ imperator on IRC (freenode)
data/Rakefile CHANGED
@@ -3,13 +3,14 @@ require 'rake/testtask'
3
3
  require 'rbconfig'
4
4
  include Config
5
5
 
6
- desc 'Install the facade package (non-gem)'
6
+ desc 'Install the facade library (non-gem)'
7
7
  task :install do
8
8
  sitelibdir = CONFIG["sitelibdir"]
9
9
  file = "lib/facade.rb"
10
10
  FileUtils.cp(file, sitelibdir, :verbose => true)
11
11
  end
12
12
 
13
+ desc 'Install the facade library as a gem'
13
14
  task :install_gem do
14
15
  ruby 'facade.gemspec'
15
16
  file = Dir["*.gem"].first
@@ -20,5 +21,4 @@ Rake::TestTask.new do |t|
20
21
  t.libs << 'test'
21
22
  t.verbose = true
22
23
  t.warning = true
23
- t.test_files = FileList['test/tc_facade.rb']
24
- end
24
+ end
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+
3
+ spec = Gem::Specification.new do |gem|
4
+ gem.name = 'facade'
5
+ gem.version = '1.0.3'
6
+ gem.author = 'Daniel J. Berger'
7
+ gem.license = 'Artistic 2.0'
8
+ gem.email = 'djberg96@gmail.com'
9
+ gem.homepage = 'http://www.rubyforge.org/projects/shards'
10
+ gem.platform = Gem::Platform::RUBY
11
+ gem.summary = 'An easy way to implement the facade pattern in your class'
12
+ gem.test_file = 'test/test_facade.rb'
13
+ gem.has_rdoc = true
14
+ gem.files = Dir['**/*'].reject{ |f| f.include?('CVS') }
15
+
16
+ gem.rubyforge_project = 'shards'
17
+ gem.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
18
+
19
+ gem.description = <<-EOF
20
+ The facade library allows you to mixin singleton methods from classes
21
+ or modules as instance methods of the extending class.
22
+ EOF
23
+ end
24
+
25
+ Gem.manage_gems if Gem::RubyGemsVersion.to_f < 1.0
26
+ Gem::Builder.new(spec).build
@@ -1,63 +1,52 @@
1
- # == Synopsis
2
- # An easy way to implement the facade pattern for your Ruby classes
3
- #
4
- # == Usage
5
- # require "facade"
6
- # class Foo < String
7
- # extend Facade
8
- # facade File, :dirname, :basename
9
- # end
10
- #
11
- # f = Foo.new("/home/djberge")
12
- # puts f.basename # 'djberge'
13
- # puts f.dirname # '/home'
14
- #
15
- # == Author
16
- # Daniel J. Berger
17
- # djberg96 at yahoo dot com
18
- # imperator on IRC (freenode)
19
- #
20
- # == Copyright
21
- # Copyright (c) 2005 Daniel J. Berger
22
- # Licensed under the same terms as Ruby itself.
23
-
24
1
  module Facade
25
- FACADE_VERSION = '1.0.2'
2
+ FACADE_VERSION = '1.0.3'
26
3
 
27
- # Forward a class or module method as an instance method of the
28
- # including class.
4
+ # The facade method will forward a singleton method as an instance
5
+ # method of the extending class. If no arguments are provided, then all
6
+ # singleton methods of the class or module become instance methods.
29
7
  #
30
- # call-seq:
31
- # forward +klass+, :method
32
- # forward +klass+, :method1, :method2, ...
8
+ # Existing instance methods are NOT overridden, but are instead ignored.
9
+ #
10
+ # Example:
11
+ #
12
+ # require 'facade'
33
13
  #
34
- # This will not override the class' existing methods.
14
+ # class MyString < String
15
+ # extend Facade
16
+ # facade File, :dirname, :basename
17
+ # end
18
+ #
19
+ # s = MyString.new('/home/djberge')
20
+ # s.basename # => 'djberge'
21
+ # s.dirname # => '/home'
35
22
  #
36
23
  def facade(klass, *methods)
37
- methods.flatten!
38
- if methods.empty? # Default to all methods
24
+ methods = methods.flatten
25
+
26
+ if methods.empty? # Default to all methods
39
27
  if klass.kind_of?(Class)
40
28
  methods = klass.methods(false)
41
29
  else
42
30
  methods = klass.public_instance_methods(false)
43
31
  end
44
32
  end
45
- methods.collect!{ |m| m.to_s } # Symbols or strings
46
- methods -= self.instance_methods # No clobber
33
+
34
+ methods.collect!{ |m| m.to_s } # Symbols or strings
35
+ methods -= self.instance_methods # No clobber
47
36
 
48
37
  methods.each do |methname|
49
38
  methname = methname.to_sym
50
- define_method(methname){ ||
39
+ define_method(methname){
51
40
  if klass.kind_of?(Class)
52
41
  meth = klass.method(methname)
53
42
  else
54
43
  meth = Object.new.extend(klass).method(methname)
55
44
  end
56
45
 
57
- if meth.arity.zero? # Zero or one argument
46
+ if meth.arity.zero? # Zero or one argument
58
47
  meth.call
59
48
  else
60
- meth.call( self )
49
+ meth.call(self)
61
50
  end
62
51
  }
63
52
  end
@@ -0,0 +1,66 @@
1
+ #########################################################################
2
+ # test_facade.rb
3
+ #
4
+ # Test suite for the Facade module. This test suite should be run via
5
+ # the 'rake test' task.
6
+ #########################################################################
7
+ require 'test/unit'
8
+ require 'facade'
9
+
10
+ module Baz
11
+ def testme(str)
12
+ str
13
+ end
14
+ end
15
+
16
+ class FooString < String
17
+ extend Facade
18
+ facade File, :basename, 'dirname'
19
+ facade Dir
20
+ facade Baz
21
+
22
+ def blockdev?
23
+ 'test'
24
+ end
25
+ end
26
+
27
+ class TC_Facade < Test::Unit::TestCase
28
+ def setup
29
+ @str = FooString.new('/home/djberge')
30
+ end
31
+
32
+ def test_facade_version
33
+ assert_equal('1.0.3', Facade::FACADE_VERSION)
34
+ end
35
+
36
+ def test_file_methods
37
+ assert_respond_to(@str, :basename)
38
+ assert_respond_to(@str, :dirname)
39
+ assert_raises(NoMethodError){ @str.executable? }
40
+ assert_raises(NoMethodError){ @str.chardev? }
41
+ end
42
+
43
+ def test_file_method_return_values
44
+ assert_equal('djberge', @str.basename)
45
+ assert_equal('/home', @str.dirname)
46
+ end
47
+
48
+ def test_dir_methods
49
+ assert_respond_to(@str, :pwd)
50
+ assert_respond_to(@str, :entries)
51
+ end
52
+
53
+ def test_no_clobber
54
+ assert_respond_to(@str, :blockdev?)
55
+ assert_equal('test', @str.blockdev?)
56
+ end
57
+
58
+ def test_module_methods
59
+ assert_respond_to(@str, :testme)
60
+ assert_equal('/home/djberge', @str.testme)
61
+ end
62
+
63
+ def teardown
64
+ @str = nil
65
+ end
66
+ end
metadata CHANGED
@@ -1,53 +1,63 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: facade
5
3
  version: !ruby/object:Gem::Version
6
- version: 1.0.2
7
- date: 2007-06-11 00:00:00 -06:00
8
- summary: An easy way to implement the facade pattern in your class
9
- require_paths:
10
- - lib
11
- email: djberg96@gmail.com
12
- homepage: http://www.rubyforge.org/projects/shards
13
- rubyforge_project:
14
- description:
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 1.0.3
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Daniel J. Berger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-21 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: " The facade library allows you to mixin singleton methods from classes\n or modules as instance methods of the extending class.\n"
17
+ email: djberg96@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ - CHANGES
25
+ - MANIFEST
31
26
  files:
32
- - lib/facade.rb
33
27
  - CHANGES
28
+ - facade.gemspec
29
+ - lib/facade.rb
34
30
  - MANIFEST
35
31
  - Rakefile
36
32
  - README
37
- - test/tc_facade.rb
38
- test_files:
39
- - test/tc_facade.rb
33
+ - test/test_facade.rb
34
+ has_rdoc: true
35
+ homepage: http://www.rubyforge.org/projects/shards
36
+ licenses:
37
+ - Artistic 2.0
38
+ post_install_message:
40
39
  rdoc_options: []
41
40
 
42
- extra_rdoc_files:
43
- - README
44
- - CHANGES
45
- - MANIFEST
46
- executables: []
47
-
48
- extensions: []
49
-
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
50
55
  requirements: []
51
56
 
52
- dependencies: []
53
-
57
+ rubyforge_project: shards
58
+ rubygems_version: 1.3.4
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: An easy way to implement the facade pattern in your class
62
+ test_files:
63
+ - test/test_facade.rb
@@ -1,65 +0,0 @@
1
- #########################################################################
2
- # tc_facade.rb
3
- #
4
- # Test suite for the Facade module. This test suite should be run via
5
- # the 'rake test' task.
6
- #########################################################################
7
- require "test/unit"
8
- require "facade"
9
-
10
- module Baz
11
- def testme(str)
12
- str
13
- end
14
- end
15
-
16
- class Foo < String
17
- extend Facade
18
- facade File, :basename, "dirname"
19
- facade Dir
20
- facade Baz
21
- def blockdev?
22
- "test"
23
- end
24
- end
25
-
26
- class TC_Facade < Test::Unit::TestCase
27
- def setup
28
- @f = Foo.new("/home/djberge")
29
- end
30
-
31
- def test_facade_version
32
- assert_equal('1.0.2', Facade::FACADE_VERSION)
33
- end
34
-
35
- def test_file_methods
36
- assert_respond_to(@f, :basename)
37
- assert_respond_to(@f, :dirname)
38
- assert_raises(NoMethodError){ @f.exists? }
39
- assert_raises(NoMethodError){ @f.chardev? }
40
- end
41
-
42
- def test_file_method_return_values
43
- assert_equal("djberge", @f.basename)
44
- assert_equal("/home", @f.dirname)
45
- end
46
-
47
- def test_dir_methods
48
- assert_respond_to(@f, :pwd)
49
- assert_respond_to(@f, :entries)
50
- end
51
-
52
- def test_no_clobber
53
- assert_respond_to(@f, :blockdev?)
54
- assert_equal("test", @f.blockdev?)
55
- end
56
-
57
- def test_module_methods
58
- assert_respond_to(@f, :testme)
59
- assert_equal("/home/djberge", @f.testme)
60
- end
61
-
62
- def teardown
63
- @f = nil
64
- end
65
- end