blank_slate 1.1.0 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 567001f8d93a8d8bb9845be407a92f367e32043838c78095bf844946e0ad8866
4
- data.tar.gz: 78bedcf0d089ec310d61f7881eb185a3e889f5bd5a65d6d5b26a6b6e33a70926
3
+ metadata.gz: 3b19c0d346d419abd6b9e1237277ed2d81d0e2485e2dee7d0e370b87a204f244
4
+ data.tar.gz: 24db981812537197620fb585ba9e747a6b9d26c0c8df5c66c3634945f6c5b284
5
5
  SHA512:
6
- metadata.gz: a86f1397bfc4166be81f3becf22638cc478862a03b860d1b9161b2c04615d574228b84a71f80c384b3917a8aa83267626fab5a93e9ba14c12b9553fbbf8b83b7
7
- data.tar.gz: d9e881744f54d53e7d7b6e43af2754e09fa759192a890a0ecbee3da99fe512030cd6d379504d4a8cc97de67e9a0c398966c51bd296de97e01e6af997b3acfcba
6
+ metadata.gz: e60ba1c59e65c5ef8929fd7cbd990b95909abb019071dd8bedc5d41739085ec1e580176899fee19eeded66a3b71df3e4cf51284cb2f35693c6821666ce779c1b
7
+ data.tar.gz: 5ba74f1d5122d6f7dd12a95b18c09332397dd3d5592c8013f2ae92cc030abc5e39561fb9359ab9164be3d3d29b6f0c8c145267ca80c437773f8c90add804e93b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ # 1.1.3
2
+
3
+ Add the ability to specify the return value on BlankSlate methods
4
+
5
+ # 1.1.2
6
+
7
+ Minor change to simplify the methods that are iterated when creating the BlankSlate class.
8
+
9
+ # 1.1.1
10
+
11
+ 1.1.0 used method_defined? which has an arity of 2 in Ruby 2.6 but 1 in previous rubies.
12
+ This was changed to check instance_methods(false)
13
+
1
14
  # 1.1.0
2
15
 
3
16
  Make BlankSlate a shallow copy of a class. Ancestor methods are preserved.
data/Gemfile CHANGED
@@ -3,5 +3,8 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :test do
6
+ gem 'minitest'
7
+ gem 'minitest-allow'
8
+ gem 'rake'
6
9
  gem 'simplecov'
7
10
  end
@@ -1,3 +1,3 @@
1
1
  module BlankSlate
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.3"
3
3
  end
data/lib/blank_slate.rb CHANGED
@@ -1,11 +1,9 @@
1
1
  module BlankSlate
2
- def BlankSlate(klass, &block)
2
+ def BlankSlate(klass, default_value: nil, &block)
3
3
  blank_slate = Class.new(klass, &block)
4
4
  blank_slate.class_eval do
5
- klass.instance_methods(false).
6
- reject{|meth| method_defined?(meth, false) }.
7
- each do |meth|
8
- define_method(meth){ nil }
5
+ (klass.instance_methods(false) - instance_methods(false)).each do |meth|
6
+ define_method(meth){ default_value }
9
7
  end
10
8
  end
11
9
  blank_slate
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
@@ -0,0 +1,69 @@
1
+ require 'test_helper'
2
+
3
+ include BlankSlate
4
+
5
+ module BlankSlate
6
+ class Parent
7
+ def inherited
8
+ "this should be inherited"
9
+ end
10
+ end
11
+
12
+ class TesterClass < Parent
13
+ def one
14
+ "one"
15
+ end
16
+ end
17
+ end
18
+
19
+ describe "BlankSlate" do
20
+ def blank_slate(&block)
21
+ BlankSlate(BlankSlate::TesterClass, &block)
22
+ end
23
+
24
+ it "returns a class with all instance_methods of the given class" do
25
+ assert_equal BlankSlate::TesterClass.instance_methods.sort, blank_slate.instance_methods.sort
26
+ end
27
+
28
+ it "sets the values of instance methods to nil" do
29
+ null_object = blank_slate.new
30
+
31
+ _(null_object.one).must_be_nil
32
+ end
33
+
34
+ it "accepts a block to define methods on the null class" do
35
+ null_object = blank_slate do
36
+ def passed_block_method
37
+ 'this is from the method defined in the block!'
38
+ end
39
+ end.new
40
+
41
+ _(null_object.passed_block_method).must_equal 'this is from the method defined in the block!'
42
+ end
43
+
44
+ it "allows the block to override method definitions from the given class" do
45
+ null_object = blank_slate do
46
+ def one
47
+ 'not the same one'
48
+ end
49
+ end.new
50
+
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
58
+ 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
+
65
+ it "uses the specified default_value for the return" do
66
+ null_object = BlankSlate(BlankSlate::TesterClass, default_value: "blank").new
67
+ assert_equal "blank", null_object.one
68
+ end
69
+ 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,57 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blank_slate
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Gay
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
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'
11
+ date: 2022-07-12 00:00:00.000000000 Z
12
+ dependencies: []
55
13
  description: |2-
56
14
 
57
15
  Create null classes based upon other classes.
@@ -60,30 +18,24 @@ description: |2-
60
18
  the behavior you designed in your other classes.
61
19
  email:
62
20
  - jim@saturnflyer.com
63
- executables:
64
- - console
65
- - setup
21
+ executables: []
66
22
  extensions: []
67
23
  extra_rdoc_files: []
68
24
  files:
69
- - ".gitignore"
70
- - ".simplecov"
71
- - ".travis.yml"
72
25
  - CHANGELOG.md
73
26
  - CODE_OF_CONDUCT.md
74
27
  - Gemfile
75
28
  - LICENSE.txt
76
29
  - README.md
77
- - Rakefile
78
- - blank_slate.gemspec
79
- - exe/console
80
- - exe/setup
81
30
  - lib/blank_slate.rb
82
31
  - lib/blank_slate/version.rb
32
+ - test/allowed.yml
33
+ - test/blank_slate_test.rb
34
+ - test/test_helper.rb
83
35
  homepage: http://github.com/saturnflyer/blank_slate
84
36
  licenses: []
85
37
  metadata: {}
86
- post_install_message:
38
+ post_install_message:
87
39
  rdoc_options: []
88
40
  require_paths:
89
41
  - lib
@@ -98,8 +50,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
50
  - !ruby/object:Gem::Version
99
51
  version: '0'
100
52
  requirements: []
101
- rubygems_version: 3.0.2
102
- signing_key:
53
+ rubygems_version: 3.3.17
54
+ signing_key:
103
55
  specification_version: 4
104
56
  summary: Impliment a null object without resorting to method_missing.
105
- test_files: []
57
+ test_files:
58
+ - test/allowed.yml
59
+ - test/blank_slate_test.rb
60
+ - test/test_helper.rb
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
- Gemfile.lock
data/.simplecov DELETED
File without changes
data/.travis.yml DELETED
@@ -1,28 +0,0 @@
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/Rakefile DELETED
@@ -1,10 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
-
4
- Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList["test/**/*_test.rb"]
8
- end
9
-
10
- task :default => :test
data/blank_slate.gemspec DELETED
@@ -1,30 +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 = Dir.chdir(File.expand_path('..', __FILE__)) do
20
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
- end
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) }
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"
30
- end
data/exe/console DELETED
@@ -1,14 +0,0 @@
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 DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here