everythingrb 0.1.0 → 0.1.1
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 +4 -4
- data/CHANGELOG.md +9 -1
- data/README.md +4 -0
- data/lib/everythingrb/core/module.rb +32 -7
- data/lib/everythingrb/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d123add89382cd34312ff1a63460d11ce0adc8d878944b961416f9b6df389560
|
4
|
+
data.tar.gz: 89de33c7ded15da7c5fdcbe1b86bdf245809124ae72fc15927b4b8c956610c7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 477ab5cd210a43f60baf7a437efa35ecf51d0b48a88e462748fe4581bb280892cf48fb7370f61ab6927b86c3adcd846bc438c113f1d7ecbbb085a2fc02ac724d
|
7
|
+
data.tar.gz: 8a92dcba15b53f3aa35ff503ee17bda989e5d6c19efb28526928e2c821f7856ecfb0404c353f7c5bc6535d1d33d27fc93fa52ea64d76a5571367480bce2507c3
|
data/CHANGELOG.md
CHANGED
@@ -13,6 +13,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
13
13
|
|
14
14
|
### Removed
|
15
15
|
|
16
|
+
|
17
|
+
## [0.1.1] - 12025-02-07
|
18
|
+
|
19
|
+
### Added
|
20
|
+
|
21
|
+
- Added `Struct` support to `Module.attr_predicate`
|
22
|
+
|
16
23
|
## [0.1.0] - 12025-01-17
|
17
24
|
|
18
25
|
### Added
|
@@ -36,5 +43,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
36
43
|
|
37
44
|
- Added alias `each` to `each_pair` in OpenStruct for better enumerable compatibility
|
38
45
|
|
39
|
-
[unreleased]: https://github.com/itsthedevman/everythingrb/compare/v0.1.
|
46
|
+
[unreleased]: https://github.com/itsthedevman/everythingrb/compare/v0.1.1...HEAD
|
47
|
+
[0.1.1]: https://github.com/itsthedevman/everythingrb/compare/v0.1.0...v0.1.1
|
40
48
|
[0.1.0]: https://github.com/itsthedevman/everythingrb/compare/5870052e137cb430d084eab1ec3934f3c50b4501...v0.1.0
|
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# EverythingRB
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/everythingrb)
|
4
|
+
[](https://github.com/everythingrb/sortsmith/actions/workflows/main.yml)
|
5
|
+

|
6
|
+
|
3
7
|
Useful extensions to Ruby core classes that you never knew you needed until now.
|
4
8
|
|
5
9
|
## Installation
|
@@ -2,24 +2,49 @@
|
|
2
2
|
|
3
3
|
class Module
|
4
4
|
#
|
5
|
-
# Creates predicate (boolean) methods
|
6
|
-
# Similar to attr_reader, attr_writer, etc.
|
5
|
+
# Creates predicate (boolean) methods that return true/false
|
6
|
+
# Similar to attr_reader, attr_writer, etc. Designed to work with
|
7
|
+
# regular classes, Struct, and Data objects.
|
8
|
+
#
|
9
|
+
# @param *attributes [Array<Symbol, String>] Attribute names
|
7
10
|
#
|
8
|
-
# @param *attributes [Array<Symbol, String>] Instance variable names
|
9
11
|
# @return [nil]
|
10
12
|
#
|
11
|
-
# @
|
13
|
+
# @raise [ArgumentError] If a predicate method of the same name already exists
|
14
|
+
#
|
15
|
+
# @example With a regular class
|
12
16
|
# class User
|
13
|
-
# attr_predicate :admin
|
17
|
+
# attr_predicate :admin
|
18
|
+
# attr_accessor :admin
|
14
19
|
# end
|
15
20
|
#
|
16
|
-
# user
|
21
|
+
# user = User.new
|
22
|
+
# user.admin? # => false
|
23
|
+
# user.admin = true
|
24
|
+
# user.admin? # => true
|
25
|
+
#
|
26
|
+
# @example With Struct/Data
|
27
|
+
# Person = Struct.new(:active)
|
28
|
+
# Person.attr_predicate(:active)
|
29
|
+
#
|
30
|
+
# person = Person.new(active: true)
|
31
|
+
# person.active? # => true
|
17
32
|
#
|
18
33
|
def attr_predicate(*attributes)
|
19
34
|
attributes.each do |attribute|
|
35
|
+
if method_defined?(:"#{attribute}?")
|
36
|
+
raise ArgumentError, "Cannot create predicate method on #{self.class} - #{attribute}? is already defined. Please choose a different name or remove the existing method."
|
37
|
+
end
|
38
|
+
|
20
39
|
module_eval <<-STR, __FILE__, __LINE__ + 1
|
21
40
|
def #{attribute}?
|
22
|
-
|
41
|
+
if instance_variable_defined?(:@#{attribute})
|
42
|
+
!!@#{attribute}
|
43
|
+
elsif respond_to?(:#{attribute})
|
44
|
+
!!self.#{attribute}
|
45
|
+
else
|
46
|
+
false
|
47
|
+
end
|
23
48
|
end
|
24
49
|
STR
|
25
50
|
end
|
data/lib/everythingrb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: everythingrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ostruct
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.6
|
19
|
+
version: '0.6'
|
20
20
|
type: :runtime
|
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: 0.6
|
26
|
+
version: '0.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: json
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|