nil_or 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: 1a5c9ed505c1f36bbfaf2e040c111ccba5ea4b5b
4
+ data.tar.gz: f5867290848fd7759065c00fbf0a87392d380953
5
+ SHA512:
6
+ metadata.gz: f4c5b30013697364e79de1b24e4fed4849f2aaa1f17d2966875cbdd7861f753dcac2fb9944079dc799d34ab72f85e8dcb061150d1bc398d84ec557483dc5edb3
7
+ data.tar.gz: 50a939a9bc87ff0e8c77edf63a394ac31f08f520e24cdfd247623717c01164ac4b8a5622a51ef0d5a671308348a6605d289616800816db680a52a36a487ec67a
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ *.sassc
4
+ .sass-cache
5
+ capybara-*.html
6
+ .rspec
7
+ /.bundle
8
+ /vendor/bundle
9
+ /log/*
10
+ /tmp/*
11
+ /db/*.sqlite3
12
+ /public/system/*
13
+ /coverage/
14
+ /spec/tmp/*
15
+ **.orig
16
+ rerun.txt
17
+ pickle-email-*.html
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in commod.gemspec
4
+ gemspec
5
+ gem 'rspec'
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ nil_or (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.3)
10
+ rspec (2.12.0)
11
+ rspec-core (~> 2.12.0)
12
+ rspec-expectations (~> 2.12.0)
13
+ rspec-mocks (~> 2.12.0)
14
+ rspec-core (2.12.1)
15
+ rspec-expectations (2.12.0)
16
+ diff-lcs (~> 1.1.3)
17
+ rspec-mocks (2.12.0)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ nil_or!
24
+ rspec
data/README.md ADDED
@@ -0,0 +1 @@
1
+ # nil_or
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/lib/nil_or.rb ADDED
@@ -0,0 +1,23 @@
1
+ module NilOr
2
+ class NilOrDelegate < BasicObject
3
+ attr_accessor :delegation_target
4
+
5
+ def initialize(delegation_target)
6
+ @delegation_target = delegation_target
7
+ end
8
+
9
+ def method_missing(method, *attributes, &block)
10
+ @delegation_target.nil? ? nil :
11
+ @delegation_target.__send__(method, *attributes, &block)
12
+ end
13
+ end
14
+
15
+ def nil_or
16
+ NilOrDelegate.new(self)
17
+ end
18
+ end
19
+
20
+ class BasicObject
21
+ include ::NilOr
22
+ end
23
+
data/nil_or.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "nil_or"
6
+ s.version = "0.0.1"
7
+ s.authors = ["Oded Niv"]
8
+ s.email = ["oded.niv@gmail.com"]
9
+ s.homepage = "https://github.com/toplex/nil_or"
10
+ s.summary = %q{Execute Unless Nil}
11
+ s.description = %q{Delegates methods to the object or returns nil.}
12
+
13
+ s.rubyforge_project = "nil_or"
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ class HistoryMock
4
+ attr_reader :calls
5
+ def initialize
6
+ @calls = []
7
+ end
8
+
9
+ def method_missing(method, *args, &block)
10
+ calls << [method, args, block]
11
+ end
12
+ end
13
+
14
+ describe NilOr do
15
+ let(:delegate) { target.nil_or }
16
+
17
+ context "nil" do
18
+ let(:target) { nil }
19
+
20
+ context "no arguments" do
21
+ context "no block" do
22
+ subject { delegate.some_attribute }
23
+ it { should be_nil }
24
+ end
25
+
26
+ context "with block" do
27
+ let(:block) { lambda { do_nothing } }
28
+ subject { delegate.some_iterator(&block) }
29
+ it { should be_nil }
30
+ end
31
+ end
32
+
33
+ context "with arguments" do
34
+ context "no block" do
35
+ subject { delegate.some_method(1, 2) }
36
+ it { should be_nil }
37
+ end
38
+
39
+ context "with block" do
40
+ let(:block) { lambda { do_nothing } }
41
+ subject { delegate.some_method(1, 2, &block) }
42
+ it { should be_nil }
43
+ end
44
+ end
45
+ end
46
+
47
+ context "not nil" do
48
+ let(:target) { HistoryMock.new }
49
+ subject { target.calls }
50
+
51
+ context "no arguments" do
52
+ context "no block" do
53
+ before { delegate.some_attribute }
54
+ it { should include([:some_attribute, [], nil]) }
55
+ end
56
+
57
+ context "with block" do
58
+ let(:block) { lambda { do_nothing } }
59
+ before { delegate.some_iterator(&block) }
60
+ it { should include([:some_iterator, [], block]) }
61
+ end
62
+ end
63
+
64
+ context "with arguments" do
65
+ context "no block" do
66
+ before { delegate.some_method(1, 2) }
67
+ it { should include([:some_method, [1, 2], nil]) }
68
+ end
69
+
70
+ context "with block" do
71
+ let(:block) { lambda { do_nothing } }
72
+ before { delegate.some_method(1, 2, &block) }
73
+ it { should include([:some_method, [1, 2], block]) }
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'nil_or'
5
+
6
+ RSpec.configure do |config|
7
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nil_or
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Oded Niv
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Delegates methods to the object or returns nil.
14
+ email:
15
+ - oded.niv@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - .gitignore
21
+ - Gemfile
22
+ - Gemfile.lock
23
+ - README.md
24
+ - Rakefile
25
+ - lib/nil_or.rb
26
+ - nil_or.gemspec
27
+ - spec/lib/nil_or_spec.rb
28
+ - spec/spec_helper.rb
29
+ homepage: https://github.com/toplex/nil_or
30
+ licenses: []
31
+ metadata: {}
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project: nil_or
48
+ rubygems_version: 2.0.3
49
+ signing_key:
50
+ specification_version: 4
51
+ summary: Execute Unless Nil
52
+ test_files:
53
+ - spec/lib/nil_or_spec.rb
54
+ - spec/spec_helper.rb