simple_delegator 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in simple_delegator.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Will Farrington
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # SimpleDelegator
2
+
3
+ Adds simple delegation to all Objects.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'simple_delegator'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install simple_delegator
18
+
19
+ ## Usage
20
+
21
+ ``` ruby
22
+ class Foo
23
+ delegate :hello, :to => :bar
24
+ delegate :goodbye, :to => :bar, :as => :hello
25
+ delegate :whatever, :as => :okay
26
+
27
+ def initialize
28
+ @bar = Bar.new
29
+ end
30
+
31
+ def okay; puts "fiiiiiine"; end
32
+ end
33
+
34
+ class Bar
35
+ def hello; puts "hello"; end
36
+ end
37
+ ```
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ begin
4
+ require "rspec/core/rake_task"
5
+
6
+ desc "Run specs"
7
+ RSpec::Core::RakeTask.new do |t|
8
+ t.rspec_opts = %w(-fs --color)
9
+ t.ruby_opts = %w(-w)
10
+ end
11
+ rescue LoadError
12
+ puts "You must run `bundle` to install development dependencies."
13
+ end
@@ -0,0 +1,5 @@
1
+ require "simple_delegator/object"
2
+
3
+ class SimpleDelegator
4
+ VERSION = "0.0.1"
5
+ end
@@ -0,0 +1,20 @@
1
+ class Object
2
+ def self.delegate(method_name, options = {})
3
+ define_method(method_name) do
4
+ to = options.fetch(:to, nil)
5
+
6
+ target = if to.nil?
7
+ self
8
+ else
9
+ if instance_variable_defined? "@#{to}"
10
+ instance_variable_get "@#{to}"
11
+ else
12
+ self.send to
13
+ end
14
+ end
15
+
16
+ new_method_name = options.fetch(:as, method_name)
17
+ target.send(new_method_name)
18
+ end
19
+ end
20
+ end
data/script/release ADDED
@@ -0,0 +1,38 @@
1
+ #!/bin/sh
2
+ # Tag and push a release.
3
+
4
+ set -e
5
+
6
+ # Make sure we're in the project root.
7
+
8
+ cd $(dirname "$0")/..
9
+
10
+ # Build a new gem archive.
11
+
12
+ rm -rf simple_delegator-*.gem
13
+ gem build -q simple_delegator.gemspec
14
+
15
+ # Make sure we're on the master branch.
16
+
17
+ (git branch | grep '* master') || {
18
+ echo "Only release from the master branch."
19
+ exit 1
20
+ }
21
+
22
+ # Figure out what version we're releasing.
23
+
24
+ tag=v`ls simple_delegator-*.gem | sed 's/^simple_delegator-\(.*\)\.gem$/\1/'`
25
+
26
+ # Make sure we haven't released this version before.
27
+
28
+ git fetch -t origin
29
+
30
+ (git tag -l | grep "$tag") && {
31
+ echo "Whoops, there's already a '${tag}' tag."
32
+ exit 1
33
+ }
34
+
35
+ # Tag it and bag it.
36
+
37
+ gem push simple_delegator-*.gem && git tag "$tag" &&
38
+ git push origin master && git push origin "$tag"
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'simple_delegator'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "simple_delegator"
8
+ gem.version = SimpleDelegator::VERSION
9
+ gem.authors = ["Will Farrington"]
10
+ gem.email = ["wfarr@github.com"]
11
+ gem.description = %q{Adds simple delegation to all Objects.}
12
+ gem.summary = %q{Adds simple delegation to all Objects.}
13
+ gem.homepage = "https://github.com/wfarr/simple_delegator"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency "mocha", "~> 0.12.7"
21
+ gem.add_development_dependency "rspec", "~> 2.11"
22
+ end
@@ -0,0 +1,36 @@
1
+ require "spec_helper"
2
+
3
+ describe SimpleDelegator do
4
+ before(:all) do
5
+ class Foo
6
+ delegate :hello, :to => :bar
7
+ delegate :goodbye, :to => :bar, :as => :hello
8
+ delegate :whatever, :as => :okay
9
+
10
+ def initialize
11
+ @bar = Bar.new
12
+ end
13
+
14
+ def okay; puts "fiiiiiine"; end
15
+ end
16
+
17
+ class Bar
18
+ def hello; puts "hello"; end
19
+ end
20
+ end
21
+
22
+ it "delegates hello to bar" do
23
+ Bar.any_instance.expects(:hello)
24
+ Foo.new.hello
25
+ end
26
+
27
+ it "delegates goodbye to bar as hello" do
28
+ Bar.any_instance.expects(:hello)
29
+ Foo.new.goodbye
30
+ end
31
+
32
+ it "delegates whatever to itself as okay" do
33
+ Foo.any_instance.expects(:okay)
34
+ Foo.new.whatever
35
+ end
36
+ end
@@ -0,0 +1,7 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'rubygems'
5
+ require 'simple_delegator'
6
+ require 'rspec'
7
+ require 'mocha_standalone'
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_delegator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Will Farrington
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mocha
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.12.7
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.12.7
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '2.11'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.11'
46
+ description: Adds simple delegation to all Objects.
47
+ email:
48
+ - wfarr@github.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - lib/simple_delegator.rb
59
+ - lib/simple_delegator/object.rb
60
+ - script/release
61
+ - simple_delegator.gemspec
62
+ - spec/simple_delegator_spec.rb
63
+ - spec/spec_helper.rb
64
+ homepage: https://github.com/wfarr/simple_delegator
65
+ licenses: []
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 1.8.23
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Adds simple delegation to all Objects.
88
+ test_files:
89
+ - spec/simple_delegator_spec.rb
90
+ - spec/spec_helper.rb