blank_slate 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -16
- data/.travis.yml +28 -0
- data/CHANGELOG.md +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +1 -2
- data/LICENSE.txt +17 -18
- data/README.md +44 -1
- data/Rakefile +6 -6
- data/blank_slate.gemspec +9 -2
- data/exe/console +14 -0
- data/exe/setup +8 -0
- data/lib/blank_slate.rb +6 -4
- data/lib/blank_slate/version.rb +1 -1
- metadata +68 -27
- data/test/lib/blank_slate_test.rb +0 -49
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 567001f8d93a8d8bb9845be407a92f367e32043838c78095bf844946e0ad8866
|
4
|
+
data.tar.gz: 78bedcf0d089ec310d61f7881eb185a3e889f5bd5a65d6d5b26a6b6e33a70926
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a86f1397bfc4166be81f3becf22638cc478862a03b860d1b9161b2c04615d574228b84a71f80c384b3917a8aa83267626fab5a93e9ba14c12b9553fbbf8b83b7
|
7
|
+
data.tar.gz: d9e881744f54d53e7d7b6e43af2754e09fa759192a890a0ecbee3da99fe512030cd6d379504d4a8cc97de67e9a0c398966c51bd296de97e01e6af997b3acfcba
|
data/.gitignore
CHANGED
@@ -1,17 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/_yardoc/
|
4
|
+
/coverage/
|
5
|
+
/doc/
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/tmp/
|
6
9
|
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/.travis.yml
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
sudo: false
|
2
|
+
before_install:
|
3
|
+
- gem update --system
|
4
|
+
- gem install bundler
|
5
|
+
language: ruby
|
6
|
+
cache: bundler
|
7
|
+
rvm:
|
8
|
+
- 2.3.6
|
9
|
+
- 2.4.4
|
10
|
+
- 2.5.3
|
11
|
+
- 2.6.1
|
12
|
+
- ruby-head
|
13
|
+
- jruby-head
|
14
|
+
env:
|
15
|
+
global:
|
16
|
+
- CC_TEST_REPORTER_ID=7cf83cb3647a2969a1af2e1bbe49155388ad3a8ff45e6b0ec9be6c1c65ea9b96
|
17
|
+
matrix:
|
18
|
+
allow_failures:
|
19
|
+
- rvm: ruby-head
|
20
|
+
- rvm: jruby-head
|
21
|
+
before_script:
|
22
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
23
|
+
- chmod +x ./cc-test-reporter
|
24
|
+
- ./cc-test-reporter before-build
|
25
|
+
script:
|
26
|
+
- bundle exec rake
|
27
|
+
after_script:
|
28
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at jim@saturnflyer.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
@@ -1,22 +1,21 @@
|
|
1
|
-
|
1
|
+
The MIT License (MIT)
|
2
2
|
|
3
|
-
|
3
|
+
Copyright (c) 2013-2019 Jim Gay
|
4
4
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
the following conditions:
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
12
11
|
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
15
14
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
OF
|
22
|
-
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -7,6 +7,9 @@ method_missing to catch every message passed. Using method_missing
|
|
7
7
|
means that your objects will respond to any method regardless of
|
8
8
|
the behavior you designed in your other related classes.
|
9
9
|
|
10
|
+
By default, a BlankSlate class will define methods to return `nil` so
|
11
|
+
you don't have to.
|
12
|
+
|
10
13
|
## Installation
|
11
14
|
|
12
15
|
Add this line to your application's Gemfile:
|
@@ -41,7 +44,7 @@ A common example of a null object is to use `method_missing` to return the objec
|
|
41
44
|
|
42
45
|
GuestPresenter = BlankSlate(UserPresenter) do
|
43
46
|
def welcome
|
44
|
-
"Sign-in or sign-up,
|
47
|
+
"Sign-in or sign-up, cowpoke!"
|
45
48
|
end
|
46
49
|
end
|
47
50
|
|
@@ -58,6 +61,46 @@ A common example of a null object is to use `method_missing` to return the objec
|
|
58
61
|
|
59
62
|
In the example above the call to `bad_method` would have continued with a null object (using method_missing) but failed for the good object. With BlankSlate, we get the behavior we want from both our regular class and the null stand-in.
|
60
63
|
|
64
|
+
### Common ancestor
|
65
|
+
|
66
|
+
BlankSlate will preserve the methods of the ancestor of the inherited class.
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
class Visitor
|
70
|
+
attr_reader :auth_info
|
71
|
+
def authenticated?
|
72
|
+
auth_info.to_h.has_key?('token')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class User < Visitor
|
77
|
+
def name
|
78
|
+
auth_info.to_h['name']
|
79
|
+
end
|
80
|
+
|
81
|
+
def email
|
82
|
+
auth_info.to_h['email']
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
class Guest < BlankSlate(Visitor)
|
87
|
+
def name
|
88
|
+
"Guest"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
user = User.new
|
93
|
+
user.auth_info = {'name' => 'Jim', 'email' => 'test@example.com', 'credentials' => 'valid stuff' }
|
94
|
+
user.name #=> "Jim"
|
95
|
+
user.authenticated? #=> true
|
96
|
+
|
97
|
+
guest = Guest.new
|
98
|
+
guest.auth_info = { }
|
99
|
+
guest.name #=> "Guest"
|
100
|
+
guest.authenticated? #=> false
|
101
|
+
|
102
|
+
```
|
103
|
+
|
61
104
|
## Contributing
|
62
105
|
|
63
106
|
1. Fork it
|
data/Rakefile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
-
require "
|
2
|
+
require "rake/testtask"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
Rake::TestTask.new(:test) do |t|
|
5
|
+
t.libs << "test"
|
6
|
+
t.libs << "lib"
|
7
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
8
8
|
end
|
9
9
|
|
10
|
-
task :default => :test
|
10
|
+
task :default => :test
|
data/blank_slate.gemspec
CHANGED
@@ -16,8 +16,15 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.summary = %q{Impliment a null object without resorting to method_missing.}
|
17
17
|
gem.homepage = "http://github.com/saturnflyer/blank_slate"
|
18
18
|
|
19
|
-
gem.files =
|
20
|
-
|
19
|
+
gem.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
21
22
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
23
|
+
gem.bindir = "exe"
|
24
|
+
gem.executables = gem.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
25
|
gem.require_paths = ["lib"]
|
26
|
+
|
27
|
+
gem.add_development_dependency "bundler", "~> 2.0"
|
28
|
+
gem.add_development_dependency "rake", "~> 10.0"
|
29
|
+
gem.add_development_dependency "minitest", "~> 5.0"
|
23
30
|
end
|
data/exe/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "blank_slate"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/exe/setup
ADDED
data/lib/blank_slate.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
module BlankSlate
|
2
2
|
def BlankSlate(klass, &block)
|
3
|
-
blank_slate = Class.new(&block)
|
3
|
+
blank_slate = Class.new(klass, &block)
|
4
4
|
blank_slate.class_eval do
|
5
|
-
klass.instance_methods(false).
|
6
|
-
|
5
|
+
klass.instance_methods(false).
|
6
|
+
reject{|meth| method_defined?(meth, false) }.
|
7
|
+
each do |meth|
|
8
|
+
define_method(meth){ nil }
|
7
9
|
end
|
8
10
|
end
|
9
11
|
blank_slate
|
10
12
|
end
|
11
|
-
end
|
13
|
+
end
|
data/lib/blank_slate/version.rb
CHANGED
metadata
CHANGED
@@ -1,64 +1,105 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blank_slate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jim Gay
|
9
8
|
autorequire:
|
10
|
-
bindir:
|
9
|
+
bindir: exe
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
date: 2019-02-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.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: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description: |2-
|
56
|
+
|
57
|
+
Create null classes based upon other classes.
|
58
|
+
This allows you to create null objects without resorting to
|
59
|
+
method_missing to catch every message passed regardless of
|
60
|
+
the behavior you designed in your other classes.
|
17
61
|
email:
|
18
62
|
- jim@saturnflyer.com
|
19
|
-
executables:
|
63
|
+
executables:
|
64
|
+
- console
|
65
|
+
- setup
|
20
66
|
extensions: []
|
21
67
|
extra_rdoc_files: []
|
22
68
|
files:
|
23
|
-
- .gitignore
|
24
|
-
- .simplecov
|
69
|
+
- ".gitignore"
|
70
|
+
- ".simplecov"
|
71
|
+
- ".travis.yml"
|
72
|
+
- CHANGELOG.md
|
73
|
+
- CODE_OF_CONDUCT.md
|
25
74
|
- Gemfile
|
26
75
|
- LICENSE.txt
|
27
76
|
- README.md
|
28
77
|
- Rakefile
|
29
78
|
- blank_slate.gemspec
|
79
|
+
- exe/console
|
80
|
+
- exe/setup
|
30
81
|
- lib/blank_slate.rb
|
31
82
|
- lib/blank_slate/version.rb
|
32
|
-
- test/lib/blank_slate_test.rb
|
33
83
|
homepage: http://github.com/saturnflyer/blank_slate
|
34
84
|
licenses: []
|
85
|
+
metadata: {}
|
35
86
|
post_install_message:
|
36
87
|
rdoc_options: []
|
37
88
|
require_paths:
|
38
89
|
- lib
|
39
90
|
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
-
none: false
|
41
91
|
requirements:
|
42
|
-
- -
|
92
|
+
- - ">="
|
43
93
|
- !ruby/object:Gem::Version
|
44
94
|
version: '0'
|
45
|
-
segments:
|
46
|
-
- 0
|
47
|
-
hash: 3761206396574154736
|
48
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
96
|
requirements:
|
51
|
-
- -
|
97
|
+
- - ">="
|
52
98
|
- !ruby/object:Gem::Version
|
53
99
|
version: '0'
|
54
|
-
segments:
|
55
|
-
- 0
|
56
|
-
hash: 3761206396574154736
|
57
100
|
requirements: []
|
58
|
-
|
59
|
-
rubygems_version: 1.8.25
|
101
|
+
rubygems_version: 3.0.2
|
60
102
|
signing_key:
|
61
|
-
specification_version:
|
103
|
+
specification_version: 4
|
62
104
|
summary: Impliment a null object without resorting to method_missing.
|
63
|
-
test_files:
|
64
|
-
- test/lib/blank_slate_test.rb
|
105
|
+
test_files: []
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
require 'minitest/spec'
|
3
|
-
require 'blank_slate'
|
4
|
-
|
5
|
-
include BlankSlate
|
6
|
-
|
7
|
-
module BlankSlate
|
8
|
-
class TesterClass
|
9
|
-
def one
|
10
|
-
"one"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "BlankSlate" do
|
16
|
-
def blank_slate(&block)
|
17
|
-
BlankSlate(BlankSlate::TesterClass, &block)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "returns a class with all instance_methods of the given class" do
|
21
|
-
assert_equal BlankSlate::TesterClass.instance_methods.sort, blank_slate.instance_methods.sort
|
22
|
-
end
|
23
|
-
|
24
|
-
it "sets the values of instance methods to nil" do
|
25
|
-
null_object = blank_slate.new
|
26
|
-
|
27
|
-
null_object.one.must_be_nil
|
28
|
-
end
|
29
|
-
|
30
|
-
it "accepts a block to define methods on the null class" do
|
31
|
-
null_object = blank_slate do
|
32
|
-
def passed_block_method
|
33
|
-
'this is from the method defined in the block!'
|
34
|
-
end
|
35
|
-
end.new
|
36
|
-
|
37
|
-
null_object.passed_block_method.must_equal 'this is from the method defined in the block!'
|
38
|
-
end
|
39
|
-
|
40
|
-
it "allows the block to override method definitions from the given class" do
|
41
|
-
null_object = blank_slate do
|
42
|
-
def one
|
43
|
-
'not the same one'
|
44
|
-
end
|
45
|
-
end.new
|
46
|
-
|
47
|
-
null_object.one.must_equal 'not the same one'
|
48
|
-
end
|
49
|
-
end
|