rrr 0.1

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.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 [maiha@wota.jp]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,35 @@
1
+ RRR
2
+ ===
3
+ A ruby library for Ruby programming with RR that allows method overload.
4
+
5
+
6
+ Methods
7
+ =======
8
+
9
+ This provides new 'cm' and 'im' class methods to Object class
10
+
11
+ * Object.cm(&block)
12
+ adds class methods
13
+
14
+ * Object.im(&block)
15
+ adds instance methods
16
+
17
+
18
+ Example
19
+ =======
20
+
21
+ require 'rrr'
22
+
23
+ class Foo
24
+ cm do
25
+ foo('x') {"called with 'x'"}
26
+ foo(numeric) {|n| "called numeric(#{n})" }
27
+ end
28
+ end
29
+
30
+ Foo.foo('x') # => "called with 'x'"
31
+ Foo.foo(1) # => "called numeric(1)"
32
+ Foo.foo # RR::Errors::DoubleNotFoundError
33
+
34
+
35
+ Copyright (c) 2009 maiha@wota.jp, released under the MIT license
@@ -0,0 +1,41 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+
4
+ GEM_NAME = "rrr"
5
+ AUTHOR = "maiha"
6
+ EMAIL = "maiha@wota.jp"
7
+ HOMEPAGE = "http://github.com/maiha/rrr"
8
+ SUMMARY = "A ruby library for Ruby programming with RR that allows method overload"
9
+ GEM_VERSION = "0.1"
10
+
11
+ spec = Gem::Specification.new do |s|
12
+ s.rubyforge_project = 'asakusa'
13
+ s.name = GEM_NAME
14
+ s.version = GEM_VERSION
15
+ s.platform = Gem::Platform::RUBY
16
+ s.has_rdoc = true
17
+ s.extra_rdoc_files = ["README", "MIT-LICENSE"]
18
+ s.summary = SUMMARY
19
+ s.description = s.summary
20
+ s.author = AUTHOR
21
+ s.email = EMAIL
22
+ s.homepage = HOMEPAGE
23
+ s.add_dependency('rrr', '>= 0.10.4')
24
+ s.require_path = 'lib'
25
+ s.files = %w(MIT-LICENSE README Rakefile) + Dir.glob("{lib,spec,app,public,stubs}/**/*")
26
+ end
27
+
28
+ Rake::GemPackageTask.new(spec) do |pkg|
29
+ pkg.gem_spec = spec
30
+ end
31
+
32
+ desc "Create a gemspec file"
33
+ task :gemspec do
34
+ File.open("#{GEM_NAME}.gemspec", "w") do |file|
35
+ file.puts spec.to_ruby
36
+ end
37
+ end
38
+
39
+ require 'spec/rake/spectask'
40
+ desc 'Default: run spec examples'
41
+ task :default => 'spec'
@@ -0,0 +1,50 @@
1
+
2
+ require 'rubygems'
3
+ require 'rr'
4
+ require 'blankslate'
5
+
6
+ module RRR
7
+ extend RR::Adapters::RRMethods
8
+
9
+ class Proxy < BlankSlate
10
+ def initialize(klass)
11
+ @klass = klass
12
+ end
13
+ end
14
+
15
+ class ClassProxy < Proxy
16
+ private
17
+ def method_missing(*args, &block)
18
+ RRR.stub(@klass).__send__(*args, &block)
19
+ end
20
+ end
21
+
22
+ class InstanceProxy < Proxy
23
+ private
24
+ def method_missing(*args, &block)
25
+ RRR.mock.instance_of(@klass).__send__(*args, &block)
26
+ end
27
+ end
28
+
29
+ def self.included(klass)
30
+ klass.class_eval do
31
+ include RR::Adapters::RRMethods
32
+ klass.extend ClassMethods
33
+ end
34
+ end
35
+
36
+ module ClassMethods
37
+ def cm(&block)
38
+ ClassProxy.new(self).__send__(:instance_eval, &block)
39
+ end
40
+
41
+ def im(&block)
42
+ InstanceProxy.new(self).__send__(:instance_eval, &block)
43
+ end
44
+ end
45
+ end
46
+
47
+ class Object
48
+ include RRR
49
+ end
50
+
@@ -0,0 +1,54 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ class Foo
4
+ cm {
5
+ bar {'bar'}
6
+
7
+ foo(1) {'foo1'}
8
+ foo('x') {'foox'}
9
+ }
10
+ end
11
+
12
+ describe "RRR" do
13
+ describe "cm" do
14
+ context "when no arged method is defined" do
15
+ it "adds class methods" do
16
+ Foo.should respond_to(:bar)
17
+ end
18
+
19
+ it "allows empty args" do
20
+ Foo.bar.should == 'bar'
21
+ end
22
+
23
+ it "ignores args" do
24
+ Foo.bar(1).should == 'bar'
25
+ end
26
+ end
27
+
28
+ context "when only immediate integer or string is defined" do
29
+ it "adds class methods" do
30
+ Foo.should respond_to(:foo)
31
+ end
32
+
33
+ it "should raise an error against empty args" do
34
+ lambda {
35
+ Foo.foo
36
+ }.should raise_error(RR::Errors::DoubleNotFoundError)
37
+ end
38
+
39
+ it "allows method overload for immediate integer" do
40
+ Foo.foo(1).should == 'foo1'
41
+ end
42
+
43
+ it "allows method overload for immediate string" do
44
+ Foo.foo('x').should == 'foox'
45
+ end
46
+
47
+ it "raise an error against symbol" do
48
+ lambda {
49
+ Foo.foo(:x)
50
+ }.should raise_error(RR::Errors::DoubleNotFoundError)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "RRR" do
4
+ describe "im" do
5
+ it "TODO" do
6
+ pending "This file should be filled with cm_spec"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+
4
+ require File.dirname(__FILE__) + '/../lib/rrr'
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rrr
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - maiha
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-27 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rrr
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.10.4
24
+ version:
25
+ description: A ruby library for Ruby programming with RR that allows method overload
26
+ email: maiha@wota.jp
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README
33
+ - MIT-LICENSE
34
+ files:
35
+ - MIT-LICENSE
36
+ - README
37
+ - Rakefile
38
+ - lib/rrr.rb
39
+ - spec/im_spec.rb
40
+ - spec/cm_spec.rb
41
+ - spec/spec_helper.rb
42
+ has_rdoc: true
43
+ homepage: http://github.com/maiha/rrr
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options: []
48
+
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project: asakusa
66
+ rubygems_version: 1.3.5
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: A ruby library for Ruby programming with RR that allows method overload
70
+ test_files: []
71
+