blank_slate 1.0.0 → 1.1.2

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
+ SHA256:
3
+ metadata.gz: 72b84dd5ad01afcfdb026bf9a830120e95a90c095fd362adcbeea433307bedec
4
+ data.tar.gz: a76f1f4e546a0c20a1f91f72b58e4d0b39880bf79ab0a0ac468b4d72513abdf2
5
+ SHA512:
6
+ metadata.gz: 8da83799e3f060a9f225a4c162c16fd60947cae61e99468e23dfe3fcdfa0d99fb88679776d904b02dae61a254115b10df2c646b532821d18f0539c3cfe946780
7
+ data.tar.gz: 4f4ab28aa58ebd5bb13084111fe4b4f60ddd901f85ac5ac8d9159ea7a9fc706031a20ed2a031eedfe58fb21c3dde462972470081e1c1685fd333494e6600832e
data/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # 1.1.2
2
+
3
+ Minor change to simplify the methods that are iterated when creating the BlankSlate class.
4
+
5
+ # 1.1.1
6
+
7
+ 1.1.0 used method_defined? which has an arity of 2 in Ruby 2.6 but 1 in previous rubies.
8
+ This was changed to check instance_methods(false)
9
+
10
+ # 1.1.0
11
+
12
+ Make BlankSlate a shallow copy of a class. Ancestor methods are preserved.
13
+
14
+ # 1.0.0
15
+
16
+ Initial release
@@ -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
@@ -3,6 +3,8 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :test do
6
+ gem 'minitest'
7
+ gem 'minitest-allow'
6
8
  gem 'rake'
7
9
  gem 'simplecov'
8
- end
10
+ end
data/LICENSE.txt CHANGED
@@ -1,22 +1,21 @@
1
- Copyright (c) 2013 'Jim Gay'
1
+ The MIT License (MIT)
2
2
 
3
- MIT License
3
+ Copyright (c) 2013-2019 Jim Gay
4
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:
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
- included in all copies or substantial portions of the Software.
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
- 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.
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, cowboy!"
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
@@ -1,3 +1,3 @@
1
1
  module BlankSlate
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.2"
3
3
  end
data/lib/blank_slate.rb CHANGED
@@ -1,11 +1,11 @@
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).each do |meth|
6
- define_method(meth){ nil } unless method_defined?(meth)
5
+ (klass.instance_methods(false) - instance_methods(false)).each do |meth|
6
+ define_method(meth){ nil }
7
7
  end
8
8
  end
9
9
  blank_slate
10
10
  end
11
- end
11
+ end
data/test/allowed.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ - BlankSlate#test_0001_returns a class with all instance_methods of the given class
3
+ - BlankSlate#test_0002_sets the values of instance methods to nil
4
+ - BlankSlate#test_0003_accepts a block to define methods on the null class
5
+ - BlankSlate#test_0004_allows the block to override method definitions from the given class
6
+ - BlankSlate#test_0005_inherits from the provide class
7
+ - BlankSlate#test_0006_preserves parent methods
@@ -1,11 +1,15 @@
1
- require 'minitest/autorun'
2
- require 'minitest/spec'
3
- require 'blank_slate'
1
+ require 'test_helper'
4
2
 
5
3
  include BlankSlate
6
4
 
7
5
  module BlankSlate
8
- class TesterClass
6
+ class Parent
7
+ def inherited
8
+ "this should be inherited"
9
+ end
10
+ end
11
+
12
+ class TesterClass < Parent
9
13
  def one
10
14
  "one"
11
15
  end
@@ -24,7 +28,7 @@ describe "BlankSlate" do
24
28
  it "sets the values of instance methods to nil" do
25
29
  null_object = blank_slate.new
26
30
 
27
- null_object.one.must_be_nil
31
+ _(null_object.one).must_be_nil
28
32
  end
29
33
 
30
34
  it "accepts a block to define methods on the null class" do
@@ -34,7 +38,7 @@ describe "BlankSlate" do
34
38
  end
35
39
  end.new
36
40
 
37
- null_object.passed_block_method.must_equal 'this is from the method defined in the block!'
41
+ _(null_object.passed_block_method).must_equal 'this is from the method defined in the block!'
38
42
  end
39
43
 
40
44
  it "allows the block to override method definitions from the given class" do
@@ -44,6 +48,17 @@ describe "BlankSlate" do
44
48
  end
45
49
  end.new
46
50
 
47
- null_object.one.must_equal 'not the same one'
51
+ _(null_object.one).must_equal 'not the same one'
52
+ end
53
+
54
+ it "inherits from the provide class" do
55
+ null_object = blank_slate.new
56
+ assert_kind_of BlankSlate::TesterClass, null_object
57
+ assert_respond_to null_object, :inherited
48
58
  end
49
- end
59
+
60
+ it "preserves parent methods" do
61
+ null_object = blank_slate.new
62
+ assert_equal null_object.inherited, 'this should be inherited'
63
+ end
64
+ end
@@ -0,0 +1,7 @@
1
+ require 'simplecov'
2
+ require "minitest/autorun"
3
+ require 'minitest/spec'
4
+ SimpleCov.start do
5
+ add_filter 'test'
6
+ end
7
+ require "blank_slate"
metadata CHANGED
@@ -1,64 +1,60 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blank_slate
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 1.1.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jim Gay
9
- autorequire:
10
- bindir: bin
8
+ autorequire:
9
+ bindir: exe
11
10
  cert_chain: []
12
- date: 2013-02-24 00:00:00.000000000 Z
11
+ date: 2022-07-12 00:00:00.000000000 Z
13
12
  dependencies: []
14
- description: ! "\n Create null classes based upon other classes.\n This allows
15
- you to create null objects without resorting to\n method_missing to catch every
16
- message passed regardless of\n the behavior you designed in your other classes."
13
+ description: |2-
14
+
15
+ Create null classes based upon other classes.
16
+ This allows you to create null objects without resorting to
17
+ method_missing to catch every message passed regardless of
18
+ the behavior you designed in your other classes.
17
19
  email:
18
20
  - jim@saturnflyer.com
19
21
  executables: []
20
22
  extensions: []
21
23
  extra_rdoc_files: []
22
24
  files:
23
- - .gitignore
24
- - .simplecov
25
+ - CHANGELOG.md
26
+ - CODE_OF_CONDUCT.md
25
27
  - Gemfile
26
28
  - LICENSE.txt
27
29
  - README.md
28
- - Rakefile
29
- - blank_slate.gemspec
30
30
  - lib/blank_slate.rb
31
31
  - lib/blank_slate/version.rb
32
- - test/lib/blank_slate_test.rb
32
+ - test/allowed.yml
33
+ - test/blank_slate_test.rb
34
+ - test/test_helper.rb
33
35
  homepage: http://github.com/saturnflyer/blank_slate
34
36
  licenses: []
35
- post_install_message:
37
+ metadata: {}
38
+ post_install_message:
36
39
  rdoc_options: []
37
40
  require_paths:
38
41
  - lib
39
42
  required_ruby_version: !ruby/object:Gem::Requirement
40
- none: false
41
43
  requirements:
42
- - - ! '>='
44
+ - - ">="
43
45
  - !ruby/object:Gem::Version
44
46
  version: '0'
45
- segments:
46
- - 0
47
- hash: 3761206396574154736
48
47
  required_rubygems_version: !ruby/object:Gem::Requirement
49
- none: false
50
48
  requirements:
51
- - - ! '>='
49
+ - - ">="
52
50
  - !ruby/object:Gem::Version
53
51
  version: '0'
54
- segments:
55
- - 0
56
- hash: 3761206396574154736
57
52
  requirements: []
58
- rubyforge_project:
59
- rubygems_version: 1.8.25
60
- signing_key:
61
- specification_version: 3
53
+ rubygems_version: 3.3.17
54
+ signing_key:
55
+ specification_version: 4
62
56
  summary: Impliment a null object without resorting to method_missing.
63
57
  test_files:
64
- - test/lib/blank_slate_test.rb
58
+ - test/allowed.yml
59
+ - test/blank_slate_test.rb
60
+ - test/test_helper.rb
data/.gitignore DELETED
@@ -1,17 +0,0 @@
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/.simplecov DELETED
File without changes
data/Rakefile DELETED
@@ -1,10 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "simplecov"
3
-
4
- desc "Test and run coverage"
5
- task :test do
6
- SimpleCov.start
7
- load 'test/lib/blank_slate_test.rb'
8
- end
9
-
10
- task :default => :test
data/blank_slate.gemspec DELETED
@@ -1,23 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'blank_slate/version'
5
-
6
- Gem::Specification.new do |gem|
7
- gem.name = "blank_slate"
8
- gem.version = BlankSlate::VERSION
9
- gem.authors = ["Jim Gay"]
10
- gem.email = ["jim@saturnflyer.com"]
11
- gem.description = %q{
12
- Create null classes based upon other classes.
13
- This allows you to create null objects without resorting to
14
- method_missing to catch every message passed regardless of
15
- the behavior you designed in your other classes.}
16
- gem.summary = %q{Impliment a null object without resorting to method_missing.}
17
- gem.homepage = "http://github.com/saturnflyer/blank_slate"
18
-
19
- gem.files = `git ls-files`.split($/)
20
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
21
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
22
- gem.require_paths = ["lib"]
23
- end