much-not-given 0.0.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b47f0b147fde4e559900f48979c58df4e27a424245ed33342dcc9dc3497fdd64
4
- data.tar.gz: d766db817beddbbd238cb1a4a9316c49bfcf0fea25a77c5f0c9de404a712151a
3
+ metadata.gz: 24237e22126fd91569e93c9fd01dee60219eb037b33ed21a8dc88ba2e5ff40fe
4
+ data.tar.gz: f9b5bbdf08003852b3b2b753180ab9ae25f59143f2922dca4bf8f06f7b3325d3
5
5
  SHA512:
6
- metadata.gz: 2665a670c0d0e3ff04f6ddd0a29e0673df2c79c77d4376a90e5371b90cd47b01835949c607e51ea9331d279e55e4000060925056bd08b0a9a6339cc599546550
7
- data.tar.gz: baea314fb721a130ead0301dd85ef3ac1b0db4d849d2a5f0b9f4eecb78c62664dc7bca9e2b9edcd8690434b8c6205c01df9e73a2ae71fe85ee48c9f092cd29c6
6
+ metadata.gz: cdf3b636f3e06a76c5fee1008e4b01eecd388271a6972f9d0955727c157ca067ea2d4375ce3724e703208e7139909591f352b4a51017ab7f8df27ad7246f789d
7
+ data.tar.gz: d250aa63a62be14d8c51babc540719d3af5db776127c69b049a0fa15d28f148945e72477dfd5667ad060f10cf205d47eb181c4e7a0d705c2a94b697d30810345
data/Gemfile CHANGED
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
- ruby "~> 2.5"
5
+ ruby ">= 2.5"
4
6
 
5
7
  gemspec
6
8
 
7
- gem "pry", "~> 0.12.2"
9
+ gem "pry"
data/README.md CHANGED
@@ -1,10 +1,33 @@
1
1
  # MuchNotGiven
2
2
 
3
- Add "not given" default values to your objects.
3
+ Add "not given" default values to your objects. This allows you to safely detect whether a method has been given argument values or not.
4
4
 
5
5
  ## Usage
6
6
 
7
- TODO: Write code samples and usage instructions here
7
+ ```ruby
8
+ module MyNamespace
9
+ include MuchNotGiven
10
+ end
11
+
12
+ MyNamespace.not_given # => MyNamespace.not_given
13
+ "some value" == MyNamespace.not_given # => false
14
+ MyNamespace.not_given?("some value") # => false
15
+ MyNamespace.not_given?(MyNamespace.not_given?) # => true
16
+ MyNamespace.given?("some value") # => true
17
+ MyNamespace.given?(MyNamespace.not_given?) # => false
18
+
19
+ def my_method(value = MyNamespace.not_given)
20
+ if MyNamespace.given?(value)
21
+ # do something with the given value
22
+ end
23
+ end
24
+
25
+ def my_method(arg_value = MyNamespace.not_given)
26
+ value = MyNamespace.given?(value) ? value : "some default value"
27
+
28
+ # do something with the optionally defaulted value
29
+ end
30
+ ```
8
31
 
9
32
  ## Installation
10
33
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MuchNotGiven
2
- VERSION = "0.0.1"
4
+ VERSION = "0.1.3"
3
5
  end
@@ -1,4 +1,53 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "much-not-given/version"
4
+ require "much-mixin"
2
5
 
3
6
  module MuchNotGiven
7
+ include MuchMixin
8
+
9
+ mixin_class_methods do
10
+ def not_given
11
+ @not_given ||=
12
+ begin
13
+ Class.new{
14
+ def initialize(receiver_name)
15
+ @receiver_name = receiver_name
16
+ end
17
+
18
+ def blank?
19
+ true
20
+ end
21
+
22
+ def present?
23
+ false
24
+ end
25
+
26
+ def to_s
27
+ "#{@receiver_name}.not_given"
28
+ end
29
+
30
+ def inspect
31
+ to_s
32
+ end
33
+
34
+ def ==(other)
35
+ if other.is_a?(self.class)
36
+ true
37
+ else
38
+ super
39
+ end
40
+ end
41
+ }.new(inspect)
42
+ end
43
+ end
44
+
45
+ def not_given?(value)
46
+ value == not_given
47
+ end
48
+
49
+ def given?(value)
50
+ value != not_given
51
+ end
52
+ end
4
53
  end
@@ -1,4 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ # frozen_string_literal: true
3
+
2
4
  lib = File.expand_path("../lib", __FILE__)
3
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
6
  require "much-not-given/version"
@@ -13,12 +15,16 @@ Gem::Specification.new do |gem|
13
15
  gem.homepage = "https://github.com/redding/much-not-given"
14
16
  gem.license = "MIT"
15
17
 
16
- gem.files = `git ls-files | grep "^[^.]"`.split($/)
18
+ gem.files = `git ls-files | grep "^[^.]"`.split($INPUT_RECORD_SEPARATOR)
19
+
17
20
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
21
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
22
  gem.require_paths = ["lib"]
20
23
 
21
- gem.required_ruby_version = "~> 2.5"
24
+ gem.required_ruby_version = ">= 2.5"
25
+
26
+ gem.add_development_dependency("assert", ["~> 2.19.2"])
27
+ gem.add_development_dependency("much-style-guide", ["~> 0.6.0"])
22
28
 
23
- gem.add_development_dependency("assert", ["~> 2.18.4"])
29
+ gem.add_dependency("much-mixin", ["~> 0.2.4"])
24
30
  end
data/test/helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # this file is automatically required when you run `assert`
2
4
  # put any test helpers here
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert/factory"
2
4
 
3
5
  module Factory
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "assert"
4
+ require "much-not-given"
5
+
6
+ module MuchNotGiven
7
+ class UnitTests < Assert::Context
8
+ desc "MuchNotGiven"
9
+ subject{ unit_module }
10
+
11
+ let(:unit_module){ MuchNotGiven }
12
+
13
+ should "inlcude MuchMixin" do
14
+ assert_that(unit_module).includes(MuchMixin)
15
+ end
16
+ end
17
+
18
+ class ReceiverTests < UnitTests
19
+ desc "reciver"
20
+ subject{ receiver_class }
21
+
22
+ let(:receiver_class) do
23
+ Class.new do
24
+ include MuchNotGiven
25
+ end
26
+ end
27
+
28
+ let(:value1) do
29
+ Factory.public_send(
30
+ [:integer, :string, :float, :time, :path, :boolean].sample,
31
+ )
32
+ end
33
+
34
+ should have_imeths :not_given, :not_given?, :given?
35
+
36
+ should "have a not_given singleton value" do
37
+ not_given = subject.not_given
38
+
39
+ assert_that(not_given.blank?).is_true
40
+ assert_that(not_given.present?).is_false
41
+ assert_that(not_given.to_s).equals("#{subject.inspect}.not_given")
42
+ assert_that(not_given.inspect).equals(not_given.to_s)
43
+
44
+ assert_that(subject.not_given).is_the_same_as(not_given)
45
+ assert_that(subject.not_given == not_given).is_true
46
+ assert_that(value1 == not_given).is_false
47
+ end
48
+
49
+ should "know if values are given or not" do
50
+ assert_that(subject.given?(value1)).is_true
51
+ assert_that(subject.given?(subject.not_given)).is_false
52
+
53
+ assert_that(subject.not_given?(value1)).is_false
54
+ assert_that(subject.not_given?(subject.not_given)).is_true
55
+ end
56
+ end
57
+ end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: much-not-given
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Redding
8
8
  - Collin Redding
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-12-23 00:00:00.000000000 Z
12
+ date: 2021-10-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: assert
@@ -17,14 +17,42 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 2.18.4
20
+ version: 2.19.2
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: 2.18.4
27
+ version: 2.19.2
28
+ - !ruby/object:Gem::Dependency
29
+ name: much-style-guide
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 0.6.0
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 0.6.0
42
+ - !ruby/object:Gem::Dependency
43
+ name: much-mixin
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: 0.2.4
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: 0.2.4
28
56
  description: Add "not given" default values to your objects.
29
57
  email:
30
58
  - kelly@kellyredding.com
@@ -43,19 +71,19 @@ files:
43
71
  - test/helper.rb
44
72
  - test/support/factory.rb
45
73
  - test/system/.keep
46
- - test/unit/.keep
74
+ - test/unit/much-not-given_tests.rb
47
75
  - tmp/.keep
48
76
  homepage: https://github.com/redding/much-not-given
49
77
  licenses:
50
78
  - MIT
51
79
  metadata: {}
52
- post_install_message:
80
+ post_install_message:
53
81
  rdoc_options: []
54
82
  require_paths:
55
83
  - lib
56
84
  required_ruby_version: !ruby/object:Gem::Requirement
57
85
  requirements:
58
- - - "~>"
86
+ - - ">="
59
87
  - !ruby/object:Gem::Version
60
88
  version: '2.5'
61
89
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -64,12 +92,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
92
  - !ruby/object:Gem::Version
65
93
  version: '0'
66
94
  requirements: []
67
- rubygems_version: 3.1.2
68
- signing_key:
95
+ rubygems_version: 3.2.29
96
+ signing_key:
69
97
  specification_version: 4
70
98
  summary: Add "not given" default values to your objects.
71
99
  test_files:
72
100
  - test/helper.rb
73
101
  - test/support/factory.rb
74
102
  - test/system/.keep
75
- - test/unit/.keep
103
+ - test/unit/much-not-given_tests.rb
data/test/unit/.keep DELETED
File without changes