delegate_it 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5d9c6c96f253f6873747b2a99c57d3f597d37396
4
+ data.tar.gz: 9eee5a76473094ed597cd28001b655513951fab1
5
+ SHA512:
6
+ metadata.gz: 34c3abf4b2e4057097d7b70dc22ac459e2068f6df944f8efed8340a40cda342fb32d55f99c0c7587808da3bc3f7a6403eace4b73f6523d4c4d0f65c80f43cfb5
7
+ data.tar.gz: a632e9635d1914e0014e74219a11806561940baacc1d02fd60b94b7ebc3fb4c7f8abcc54df8776e02b4d55c1e846e51768e46f9c3b25f6d41e1188e8ddf0123a
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ Gemfile.lock
2
+ .ruby-version
3
+ pkg/
4
+ *.gem
5
+ coverage/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 2.0.0
4
+ - 2.1.1
5
+ - 2.2.0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 pawurb
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,3 @@
1
+ # Delegate_it
2
+
3
+ Delegate_it gem provides an easy way to use ActiveSupport like `delegate` method in your non Rails projects.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'delegate_it/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "delegate_it"
8
+ gem.version = DelegateIt::VERSION
9
+ gem.authors = ["pawurb"]
10
+ gem.email = ["p.urbanek89@gmail.com"]
11
+ gem.summary = %q{ Use delegate method without ActiveSupport }
12
+ gem.description = %q{ Delegate_it gem provides an easy way to use ActiveSupport like delegate method in your non Rails projects }
13
+ gem.homepage = "http://github.com/pawurb/delegate_it"
14
+ gem.files = `git ls-files`.split("\n")
15
+ gem.test_files = gem.files.grep(%r{^(spec)/})
16
+ gem.require_paths = ["lib"]
17
+ gem.license = "MIT"
18
+ gem.add_development_dependency "rspec"
19
+ gem.add_development_dependency "rake"
20
+ gem.add_development_dependency "coveralls"
21
+ end
@@ -0,0 +1,5 @@
1
+ require 'delegate_it/main'
2
+ require 'delegate_it/version'
3
+
4
+ module DelegateIt
5
+ end
@@ -0,0 +1,35 @@
1
+ #encoding: UTF-8
2
+ module DelegateIt
3
+ def self.included(klass)
4
+ klass.instance_eval do
5
+ def delegate *methods, options
6
+ @@delegated_settings ||= []
7
+ methods.each do |method|
8
+ @@delegated_settings.push(Struct.new(:name, :options).new(method, options))
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ def method_missing(method, *)
15
+ setting = @@delegated_settings.select do |s|
16
+ s.name == method
17
+ end.first
18
+
19
+ if setting
20
+ receiver = if self.respond_to?(setting.options[:to])
21
+ self.send(setting.options[:to])
22
+ else
23
+ nil
24
+ end
25
+
26
+ if setting.options[:allow_nil] && !receiver
27
+ nil
28
+ else
29
+ receiver.send(method)
30
+ end
31
+ else
32
+ super
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module DelegateIt
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,52 @@
1
+ #encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ class Dummy
5
+ include DelegateIt
6
+ delegate :name, to: :name_delegate
7
+ delegate :hello, to: :no_exist, allow_nil: true
8
+ delegate :there, to: :there_delegate, allow_nil: true
9
+
10
+ def name_delegate
11
+ Struct.new(:name).new('name_val')
12
+ end
13
+
14
+ def there_delegate
15
+ Struct.new(:there).new('there_val')
16
+ end
17
+ end
18
+
19
+ describe 'DelegateIt' do
20
+ subject do
21
+ Dummy.new
22
+ end
23
+
24
+ describe "standard delegation" do
25
+ it "works" do
26
+ expect(subject.name).to eq 'name_val'
27
+ end
28
+ end
29
+
30
+ describe "allow_nil case" do
31
+ context "receiver is nil" do
32
+ it "returns nil" do
33
+ expect(subject.hello).to eq nil
34
+ end
35
+ end
36
+
37
+ context "receiver exists" do
38
+ it "delegates like usual" do
39
+ expect(subject.there).to eq 'there_val'
40
+ end
41
+ end
42
+ end
43
+
44
+ describe "method does not exist" do
45
+ it "raises no_method error" do
46
+ expect do
47
+ subject.not_there
48
+ end.to raise_error(NoMethodError)
49
+ end
50
+ end
51
+ end
52
+
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require_relative '../lib/delegate_it'
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: delegate_it
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - pawurb
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: coveralls
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: " Delegate_it gem provides an easy way to use ActiveSupport like delegate
56
+ method in your non Rails projects "
57
+ email:
58
+ - p.urbanek89@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - delegate_it.gemspec
71
+ - lib/delegate_it.rb
72
+ - lib/delegate_it/main.rb
73
+ - lib/delegate_it/version.rb
74
+ - spec/delegate_it/main_spec.rb
75
+ - spec/spec_helper.rb
76
+ homepage: http://github.com/pawurb/delegate_it
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.4.6
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Use delegate method without ActiveSupport
100
+ test_files:
101
+ - spec/delegate_it/main_spec.rb
102
+ - spec/spec_helper.rb