attr_bool 0.2.1 → 0.2.2

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: 157027292cdc404395192f6372dca22a286c93a25a8be537e762f45f22c72ffe
4
- data.tar.gz: 9922d7205c2b06d5a0a63fb5fff54f6c8901a43c082435645be514ff3a5cee16
3
+ metadata.gz: b0746e6bd74e2e6b5b07d6c910a13e18a97de02188f16b237ec810921e93aa97
4
+ data.tar.gz: 6c071fb31a8ea5a63e8b875e7907259ae9b9694cc31d11ae9f6c503544e111f2
5
5
  SHA512:
6
- metadata.gz: 2a729e5654e55f3952556251ec67490dd9bb20ddd45b0564336fad0d24c38d1a8f862f03d04bb075debbd02851a33de35fbc9e02d9770a78f2bc35b9a7ee6d12
7
- data.tar.gz: 1dab140de4d8f01fb50870117a775dc522c63426118c6f78cd71076da2769b1874217586f79e7288542f2f71b63f8f23b3857b01fc5fa5eb8e4fa7ea58a279c4
6
+ metadata.gz: a93798cf5ac76b8a181f9dff137255a93b59be01a92f02fb57723ba0ca9ffe1a3a6d470e03caaea067a20498c4338b2c1415c2fa015a25da9e04442763a74dee
7
+ data.tar.gz: ce15f10ea56ea61fe14aaca334d521f84869386769f0ec97e50ec720c7ccf94f35f32d66860c1126c97c8319a7c03a2eb6e4fdd35ee9211e6dde7916a8f7b6e2
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020 Jonathan Bradley Whited
3
+ Copyright (c) 2020-2021 Jonathan Bradley Whited
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/Rakefile CHANGED
@@ -1,17 +1,6 @@
1
1
  # encoding: UTF-8
2
2
  # frozen_string_literal: true
3
3
 
4
- #--
5
- # This file is part of AttrBool.
6
- # Copyright (c) 2020 Jonathan Bradley Whited (@esotericpig)
7
- #
8
- # AttrBool is free software: you can redistribute it and/or modify it under
9
- # the terms of the MIT License.
10
- #
11
- # You should have received a copy of the MIT License along with AttrBool.
12
- # If not, see <https://choosealicense.com/licenses/mit/>.
13
- #++
14
-
15
4
 
16
5
  require 'bundler/gem_tasks'
17
6
 
@@ -28,20 +17,21 @@ CLOBBER.include('doc/')
28
17
  task default: [:test]
29
18
 
30
19
  desc 'Generate doc'
31
- task :doc => [:yard] do |task|
20
+ task :doc,%i[] => %i[yard] do |task|
21
+ # pass
32
22
  end
33
23
 
34
24
  desc 'Generate doc for tests too'
35
25
  task :doc_test do |task|
36
26
  ENV['doctest'] = 'y'
37
-
27
+
38
28
  doc_task = Rake::Task[:doc]
39
-
40
- doc_task.reenable()
41
- doc_task.invoke()
29
+
30
+ doc_task.reenable
31
+ doc_task.invoke
42
32
  end
43
33
 
44
- Rake::TestTask.new() do |task|
34
+ Rake::TestTask.new do |task|
45
35
  task.deps << :doc_test
46
36
  task.libs = ['lib','test']
47
37
  task.pattern = File.join('test','**','*_test.rb')
@@ -50,77 +40,79 @@ Rake::TestTask.new() do |task|
50
40
  task.warning = true
51
41
  end
52
42
 
53
- YARD::Rake::YardocTask.new() do |task|
43
+ YARD::Rake::YardocTask.new do |task|
54
44
  task.files = [File.join('lib','**','*.{rb}')]
55
-
45
+
56
46
  #task.options += ['--template-path',File.join('yard','templates')]
57
47
  task.options += ['--title',"AttrBool v#{AttrBool::VERSION} doc"]
58
-
59
- task.before = Proc.new() do
60
- task.files << File.join('test','**','*.{rb}') if ENV['doctest'].to_s().casecmp?('y')
48
+
49
+ task.before = proc do
50
+ task.files << File.join('test','**','*.{rb}') if ENV['doctest'].to_s.casecmp?('y')
61
51
  end
62
52
  end
63
53
 
64
54
  desc 'Benchmark define_method vs module_eval and ?: vs bangbang'
65
55
  task :benchmark do |task|
56
+ # rubocop:disable all
57
+
66
58
  N0 = 100_000
67
59
  N1 = 20_000_000
68
-
60
+
69
61
  module ModuleExt
70
62
  def do_class_eval(name)
71
63
  0.upto(N0) do |i|
72
64
  n = "#{name}#{i}"
73
-
65
+
74
66
  class_eval("def #{n}?(); @#{n}; end")
75
67
  end
76
68
  end
77
-
69
+
78
70
  def do_define_method(name)
79
71
  0.upto(N0) do |i|
80
72
  n = "#{name}#{i}"
81
-
73
+
82
74
  define_method(:"#{n}?") do
83
75
  instance_variable_get(:"@#{n}")
84
76
  end
85
77
  end
86
78
  end
87
-
79
+
88
80
  def do_module_eval(name)
89
81
  0.upto(N0) do |i|
90
82
  n = "#{name}#{i}"
91
-
83
+
92
84
  module_eval("def #{n}?(); @#{n}; end")
93
85
  end
94
86
  end
95
87
  end
96
-
88
+
97
89
  Module.prepend ModuleExt
98
-
90
+
99
91
  puts
100
- Benchmark.bmbm() do |bm|
92
+ Benchmark.bmbm do |bm|
101
93
  bm.report('class_eval ') do
102
94
  class ClassEvalTest
103
95
  do_class_eval :ce
104
96
  end
105
97
  end
106
-
98
+
107
99
  bm.report('define_method') do
108
100
  class DefineMethodTest
109
101
  do_define_method :dm
110
102
  end
111
103
  end
112
-
104
+
113
105
  bm.report('module_eval ') do
114
106
  class ModuleEvalTest
115
107
  do_module_eval :me
116
108
  end
117
109
  end
118
110
  end
119
-
111
+
120
112
  str = 'str' # Warning workaround
121
-
113
+
122
114
  puts
123
- Benchmark.bmbm() do |bm|
115
+ Benchmark.bmbm do |bm|
124
116
  bm.report('?:') do
125
117
  0.upto(N1) do |i|
126
118
  x = str ? true : false
@@ -130,7 +122,7 @@ task :benchmark do |task|
130
122
  x = x ? true : false
131
123
  end
132
124
  end
133
-
125
+
134
126
  bm.report('!!') do
135
127
  0.upto(N1) do |i|
136
128
  y = !!str
@@ -141,6 +133,8 @@ task :benchmark do |task|
141
133
  end
142
134
  end
143
135
  end
144
-
136
+
145
137
  puts
138
+
139
+ # rubocop:enable all
146
140
  end
data/attr_bool.gemspec CHANGED
@@ -1,62 +1,51 @@
1
1
  # encoding: UTF-8
2
2
  # frozen_string_literal: true
3
3
 
4
- #--
5
- # This file is part of AttrBool.
6
- # Copyright (c) 2020 Jonathan Bradley Whited (@esotericpig)
7
- #
8
- # AttrBool is free software: you can redistribute it and/or modify it under
9
- # the terms of the MIT License.
10
- #
11
- # You should have received a copy of the MIT License along with AttrBool.
12
- # If not, see <https://choosealicense.com/licenses/mit/>.
13
- #++
14
-
15
4
 
16
5
  require_relative 'lib/attr_bool/version'
17
6
 
18
- Gem::Specification.new() do |spec|
7
+ Gem::Specification.new do |spec|
19
8
  spec.name = 'attr_bool'
20
9
  spec.version = AttrBool::VERSION
21
- spec.authors = ['Jonathan Bradley Whited (@esotericpig)']
22
- spec.email = ['bradley@esotericpig.com']
10
+ spec.authors = ['Jonathan Bradley Whited']
11
+ spec.email = ['code@esotericpig.com']
23
12
  spec.licenses = ['MIT']
24
13
  spec.homepage = 'https://github.com/esotericpig/attr_bool'
25
14
  spec.summary = 'Finally attr_accessor & attr_reader with question marks for booleans!?'
26
- spec.description = <<-EOD.gsub(/\s+/,' ').strip()
15
+ spec.description = <<-DESC.gsub(/\s+/,' ').strip
27
16
  #{spec.summary}
28
17
  Simply use: attr_accessor?, attr_reader?, attr_bool, attr_bool?.
29
18
  Default values can also be passed in as the last argument
30
19
  or with the 'default: ' keyword argument.
31
20
  In a Module/Class, extend 'AttrBool::Ext',
32
21
  or in the file, require 'attr_bool/core_ext'.
33
- EOD
34
-
22
+ DESC
23
+
35
24
  spec.metadata = {
36
25
  'homepage_uri' => 'https://github.com/esotericpig/attr_bool',
37
26
  'source_code_uri' => 'https://github.com/esotericpig/attr_bool',
38
27
  'bug_tracker_uri' => 'https://github.com/esotericpig/attr_bool/issues',
39
28
  'changelog_uri' => 'https://github.com/esotericpig/attr_bool/blob/master/CHANGELOG.md',
40
29
  }
41
-
30
+
42
31
  spec.required_ruby_version = '>= 2.4'
43
32
  spec.require_paths = ['lib']
44
-
33
+
45
34
  spec.files = [
46
35
  Dir.glob(File.join("{#{spec.require_paths.join(',')}}",'**','*.{erb,rb}')),
47
36
  %W[ Gemfile #{spec.name}.gemspec Rakefile ],
48
37
  %w[ LICENSE.txt ],
49
- ].flatten()
50
-
51
- spec.add_development_dependency 'bundler' ,'~> 2.1'
38
+ ].flatten
39
+
40
+ spec.add_development_dependency 'bundler' ,'~> 2.2'
52
41
  spec.add_development_dependency 'minitest' ,'~> 5.14'
53
42
  spec.add_development_dependency 'rake' ,'~> 13.0'
54
- spec.add_development_dependency 'rdoc' ,'~> 6.2' # YARDoc RDoc (*.rb)
43
+ spec.add_development_dependency 'rdoc' ,'~> 6.3' # YARDoc RDoc (*.rb)
55
44
  spec.add_development_dependency 'redcarpet' ,'~> 3.5' # YARDoc Markdown (*.md)
56
45
  spec.add_development_dependency 'yard' ,'~> 0.9' # Doc
57
-
46
+
58
47
  spec.extra_rdoc_files = %w[ LICENSE.txt ]
59
-
48
+
60
49
  spec.rdoc_options = [
61
50
  '--hyperlink-all','--show-hash',
62
51
  '--title',"AttrBool v#{AttrBool::VERSION} Doc",
data/lib/attr_bool.rb CHANGED
@@ -1,23 +1,18 @@
1
- #!/usr/bin/env ruby
2
1
  # encoding: UTF-8
3
2
  # frozen_string_literal: true
4
3
 
5
4
  #--
6
5
  # This file is part of AttrBool.
7
- # Copyright (c) 2020 Jonathan Bradley Whited (@esotericpig)
8
- #
9
- # AttrBool is free software: you can redistribute it and/or modify it under
10
- # the terms of the MIT License.
11
- #
12
- # You should have received a copy of the MIT License along with AttrBool.
13
- # If not, see <https://choosealicense.com/licenses/mit/>.
6
+ # Copyright (c) 2020-2021 Jonathan Bradley Whited
7
+ #
8
+ # SPDX-License-Identifier: MIT
14
9
  #++
15
10
 
16
11
 
17
12
  require 'attr_bool/version'
18
13
 
19
14
  ###
20
- # @author Jonathan Bradley Whited (@esotericpig)
15
+ # @author Jonathan Bradley Whited
21
16
  # @since 0.1.0
22
17
  ###
23
18
  module AttrBool
@@ -26,47 +21,47 @@ module AttrBool
26
21
  # I found the following to be the case on my system:
27
22
  # - +define_method+ is faster than +module_eval+ & +class_eval+
28
23
  # - +? true : false+ (ternary operator) is faster than +!!+ (surprisingly)
29
- #
24
+ #
30
25
  # To run benchmark code:
31
26
  # $ bundle exec rake benchmark
32
- #
33
- # @author Jonathan Bradley Whited (@esotericpig)
27
+ #
28
+ # @author Jonathan Bradley Whited
34
29
  # @since 0.2.0
35
30
  ###
36
31
  module Ext
37
32
  def attr_accessor?(*var_ids,default: nil,reader: nil,writer: nil,&block)
38
33
  if block
39
- reader = block if reader.nil?()
40
- writer = block if writer.nil?()
34
+ reader = block if reader.nil?
35
+ writer = block if writer.nil?
41
36
  end
42
-
43
- if default.nil?() && reader.nil?()
37
+
38
+ if default.nil? && reader.nil?
44
39
  last = var_ids[-1]
45
-
40
+
46
41
  if !last.is_a?(String) && !last.is_a?(Symbol)
47
- default = var_ids.pop()
42
+ default = var_ids.pop
48
43
  end
49
44
  end
50
-
45
+
51
46
  attr_reader?(*var_ids,default: default,&reader)
52
47
  attr_writer?(*var_ids,&writer)
53
48
  end
54
-
49
+
55
50
  def attr_reader?(*var_ids,default: nil,&block)
56
- no_default = (default.nil?() && !block)
57
-
51
+ no_default = (default.nil? && !block)
52
+
58
53
  if no_default
59
54
  last = var_ids[-1]
60
-
55
+
61
56
  if !last.is_a?(String) && !last.is_a?(Symbol)
62
- default = var_ids.pop()
57
+ default = var_ids.pop
63
58
  no_default = false
64
59
  end
65
60
  end
66
-
67
- var_ids.each() do |var_id|
61
+
62
+ var_ids.each do |var_id|
68
63
  var_id_q = :"#{var_id}?"
69
-
64
+
70
65
  if no_default
71
66
  define_method(var_id_q) do
72
67
  instance_variable_get(:"@#{var_id}")
@@ -76,7 +71,7 @@ module AttrBool
76
71
  define_method(var_id_q,&block)
77
72
  else
78
73
  at_var_id = :"@#{var_id}"
79
-
74
+
80
75
  define_method(var_id_q) do
81
76
  instance_variable_defined?(at_var_id) ? instance_variable_get(at_var_id) : default
82
77
  end
@@ -84,64 +79,64 @@ module AttrBool
84
79
  end
85
80
  end
86
81
  end
87
-
82
+
88
83
  # This should only be used when you want to pass in a block/proc.
89
84
  def attr_writer?(*var_ids,&block)
90
85
  if block
91
- var_ids.each() do |var_id|
86
+ var_ids.each do |var_id|
92
87
  define_method(:"#{var_id}=",&block)
93
88
  end
94
89
  else
95
90
  last = var_ids[-1]
96
-
91
+
97
92
  if !last.is_a?(String) && !last.is_a?(Symbol)
98
93
  raise ArgumentError,'default value not allowed for writer'
99
94
  end
100
-
95
+
101
96
  attr_writer(*var_ids)
102
97
  end
103
98
  end
104
-
99
+
105
100
  def attr_bool(*var_ids,default: nil,reader: nil,writer: nil,&block)
106
101
  if block
107
- reader = block if reader.nil?()
108
- writer = block if writer.nil?()
102
+ reader = block if reader.nil?
103
+ writer = block if writer.nil?
109
104
  end
110
-
111
- if default.nil?() && reader.nil?()
105
+
106
+ if default.nil? && reader.nil?
112
107
  last = var_ids[-1]
113
-
108
+
114
109
  if !last.is_a?(String) && !last.is_a?(Symbol)
115
- default = var_ids.pop()
110
+ default = var_ids.pop
116
111
  end
117
112
  end
118
-
113
+
119
114
  attr_bool?(*var_ids,default: default,&reader)
120
115
  attr_booler(*var_ids,&writer)
121
116
  end
122
117
  alias_method :attr_boolor,:attr_bool
123
-
118
+
124
119
  def attr_bool?(*var_ids,default: nil,&block)
125
- no_default = default.nil?()
126
-
120
+ no_default = default.nil?
121
+
127
122
  if no_default
128
123
  no_default = !block
129
-
124
+
130
125
  if no_default
131
126
  last = var_ids[-1]
132
-
127
+
133
128
  if !last.is_a?(String) && !last.is_a?(Symbol)
134
- default = var_ids.pop() ? true : false
129
+ default = var_ids.pop ? true : false
135
130
  no_default = false
136
131
  end
137
132
  end
138
133
  else
139
134
  default = default ? true : false
140
135
  end
141
-
142
- var_ids.each() do |var_id|
136
+
137
+ var_ids.each do |var_id|
143
138
  var_id_q = :"#{var_id}?"
144
-
139
+
145
140
  if no_default
146
141
  define_method(var_id_q) do
147
142
  instance_variable_get(:"@#{var_id}") ? true : false
@@ -151,7 +146,7 @@ module AttrBool
151
146
  define_method(var_id_q,&block)
152
147
  else
153
148
  at_var_id = :"@#{var_id}"
154
-
149
+
155
150
  define_method(var_id_q) do
156
151
  if instance_variable_defined?(at_var_id)
157
152
  instance_variable_get(at_var_id) ? true : false
@@ -163,19 +158,19 @@ module AttrBool
163
158
  end
164
159
  end
165
160
  end
166
-
161
+
167
162
  def attr_booler(*var_ids,&block)
168
163
  if !block
169
164
  last = var_ids[-1]
170
-
165
+
171
166
  if !last.is_a?(String) && !last.is_a?(Symbol)
172
167
  raise ArgumentError,'default value not allowed for writer'
173
168
  end
174
169
  end
175
-
176
- var_ids.each() do |var_id|
170
+
171
+ var_ids.each do |var_id|
177
172
  var_id_eq = :"#{var_id}="
178
-
173
+
179
174
  if block
180
175
  define_method(var_id_eq,&block)
181
176
  else
@@ -1,16 +1,11 @@
1
- #!/usr/bin/env ruby
2
1
  # encoding: UTF-8
3
2
  # frozen_string_literal: true
4
3
 
5
4
  #--
6
5
  # This file is part of AttrBool.
7
- # Copyright (c) 2020 Jonathan Bradley Whited (@esotericpig)
8
- #
9
- # AttrBool is free software: you can redistribute it and/or modify it under
10
- # the terms of the MIT License.
11
- #
12
- # You should have received a copy of the MIT License along with AttrBool.
13
- # If not, see <https://choosealicense.com/licenses/mit/>.
6
+ # Copyright (c) 2020-2021 Jonathan Bradley Whited
7
+ #
8
+ # SPDX-License-Identifier: MIT
14
9
  #++
15
10
 
16
11
 
@@ -18,7 +13,7 @@ require 'attr_bool'
18
13
 
19
14
  module AttrBool
20
15
  ###
21
- # @author Jonathan Bradley Whited (@esotericpig)
16
+ # @author Jonathan Bradley Whited
22
17
  # @since 0.2.0
23
18
  ###
24
19
  module CoreExt
@@ -1,19 +1,14 @@
1
- #!/usr/bin/env ruby
2
1
  # encoding: UTF-8
3
2
  # frozen_string_literal: true
4
3
 
5
4
  #--
6
5
  # This file is part of AttrBool.
7
- # Copyright (c) 2020 Jonathan Bradley Whited (@esotericpig)
8
- #
9
- # AttrBool is free software: you can redistribute it and/or modify it under
10
- # the terms of the MIT License.
11
- #
12
- # You should have received a copy of the MIT License along with AttrBool.
13
- # If not, see <https://choosealicense.com/licenses/mit/>.
6
+ # Copyright (c) 2020-2021 Jonathan Bradley Whited
7
+ #
8
+ # SPDX-License-Identifier: MIT
14
9
  #++
15
10
 
16
11
 
17
12
  module AttrBool
18
- VERSION = '0.2.1'
13
+ VERSION = '0.2.2'
19
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attr_bool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
- - Jonathan Bradley Whited (@esotericpig)
8
- autorequire:
7
+ - Jonathan Bradley Whited
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-07 00:00:00.000000000 Z
11
+ date: 2021-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.1'
19
+ version: '2.2'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.1'
26
+ version: '2.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '6.2'
61
+ version: '6.3'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '6.2'
68
+ version: '6.3'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: redcarpet
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -99,7 +99,7 @@ description: 'Finally attr_accessor & attr_reader with question marks for boolea
99
99
  can also be passed in as the last argument or with the ''default: '' keyword argument.
100
100
  In a Module/Class, extend ''AttrBool::Ext'', or in the file, require ''attr_bool/core_ext''.'
101
101
  email:
102
- - bradley@esotericpig.com
102
+ - code@esotericpig.com
103
103
  executables: []
104
104
  extensions: []
105
105
  extra_rdoc_files:
@@ -120,12 +120,12 @@ metadata:
120
120
  source_code_uri: https://github.com/esotericpig/attr_bool
121
121
  bug_tracker_uri: https://github.com/esotericpig/attr_bool/issues
122
122
  changelog_uri: https://github.com/esotericpig/attr_bool/blob/master/CHANGELOG.md
123
- post_install_message:
123
+ post_install_message:
124
124
  rdoc_options:
125
125
  - "--hyperlink-all"
126
126
  - "--show-hash"
127
127
  - "--title"
128
- - AttrBool v0.2.1 Doc
128
+ - AttrBool v0.2.2 Doc
129
129
  require_paths:
130
130
  - lib
131
131
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -139,8 +139,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  - !ruby/object:Gem::Version
140
140
  version: '0'
141
141
  requirements: []
142
- rubygems_version: 3.1.2
143
- signing_key:
142
+ rubygems_version: 3.2.15
143
+ signing_key:
144
144
  specification_version: 4
145
145
  summary: Finally attr_accessor & attr_reader with question marks for booleans!?
146
146
  test_files: []