everythingrb 0.1.0 → 0.1.2

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: 43920acf56e9d77e9897c581c1e4ad347e4f349eb1222d32a88a2205a6c3168e
4
- data.tar.gz: 870ff0e384224fd9f266da3ca2000dd273a850978a2dbde56a305cc98349cb0d
3
+ metadata.gz: f89e80920d664c010fe41afbc614d77ed2d45e16cef5a88a67a4c953a492c2b5
4
+ data.tar.gz: 34940dce0a2fa7f374642bc046f619789bc698deea66ef94a4c55f6743c5a44e
5
5
  SHA512:
6
- metadata.gz: 46cee04bf8d80f1bb4afe92c80aa56f4538c2100066ea6fda229e91244ba53f1cce67e98e59b8e50767ad9a5a3c21cef3c5da530d9fb10a557c70b5f27238429
7
- data.tar.gz: 5ba5dd8f119ee5bdee72291d8df5c7d8f33ef6b50320fe7e639745933f3125b6eca0fa15f19b54eb66d443a38642121bb649ce2815fe0d6477ee3dbd2ec0ce3e
6
+ metadata.gz: 95811ed4b2df3ba3cbec346139c606421b11935bfc37fa0ff3874edae00a40ed9b358551d11f86d6dba12979131f84050fe9fd96edeea11e24767f013964bec4
7
+ data.tar.gz: cc9655f063282b211ff79c3308d814f598d8131b4a86b1c15ec76a7f8563e590fc96f2e22e8a1e467a650769f765ecb8676705fb2b56d2781ac14b0c2448bed8
data/CHANGELOG.md CHANGED
@@ -13,6 +13,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
13
13
 
14
14
  ### Removed
15
15
 
16
+ ## [0.1.2] - 12025-02-11
17
+
18
+ ### Added
19
+
20
+ - Added `#presence` support to `Module.attr_predicate` if `ActiveSupport` is loaded.
21
+
22
+ ### Changed
23
+
24
+ - Separated out tests that require `ActiveSupport` into their own test process. Files that end with `_active_support` will be tested separately with ActiveSupport loaded
25
+
26
+
27
+ ## [0.1.1] - 12025-02-07
28
+
29
+ ### Added
30
+
31
+ - Added `Struct` support to `Module.attr_predicate`
32
+
16
33
  ## [0.1.0] - 12025-01-17
17
34
 
18
35
  ### Added
@@ -36,5 +53,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
36
53
 
37
54
  - Added alias `each` to `each_pair` in OpenStruct for better enumerable compatibility
38
55
 
39
- [unreleased]: https://github.com/itsthedevman/everythingrb/compare/v0.1.0...HEAD
56
+ [unreleased]: https://github.com/itsthedevman/everythingrb/compare/v0.1.2...HEAD
57
+ [0.1.2]: https://github.com/itsthedevman/everythingrb/compare/v0.1.1...v0.1.2
58
+ [0.1.1]: https://github.com/itsthedevman/everythingrb/compare/v0.1.0...v0.1.1
40
59
  [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
+ [![Gem Version](https://badge.fury.io/rb/everythingrb.svg)](https://badge.fury.io/rb/everythingrb)
4
+ [![Tests](https://github.com/itsthedevman/everythingrb/actions/workflows/main.yml/badge.svg)](https://github.com/everythingrb/sortsmith/actions/workflows/main.yml)
5
+ ![Ruby Version](https://img.shields.io/badge/ruby-3.3.6-ruby)
6
+
3
7
  Useful extensions to Ruby core classes that you never knew you needed until now.
4
8
 
5
9
  ## Installation
data/Rakefile CHANGED
@@ -3,8 +3,17 @@
3
3
  require "bundler/gem_tasks"
4
4
  require "minitest/test_task"
5
5
 
6
- Minitest::TestTask.create
6
+ Minitest::TestTask.create(:test_regular) do |t|
7
+ # I couldn't get extra_args to work
8
+ t.test_globs = Dir.glob("test/**/test_*.rb").reject { |f| f.include?("active_support") }
9
+ end
10
+
11
+ Minitest::TestTask.create(:test_active_support) do |t|
12
+ t.test_globs = ["test/**/test_*_active_support.rb"]
13
+ t.test_prelude = "ENV[\"LOAD_ACTIVE_SUPPORT\"] = \"true\""
14
+ end
7
15
 
8
16
  require "standard/rake"
9
17
 
18
+ task test: [:test_regular, :test_active_support]
10
19
  task default: %i[test standard]
@@ -2,26 +2,56 @@
2
2
 
3
3
  class Module
4
4
  #
5
- # Creates predicate (boolean) methods for instance variables
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
+ # Note: If ActiveSupport is loaded, this will check if the value is present? instead of truthy
10
+ #
11
+ # @param *attributes [Array<Symbol, String>] Attribute names
7
12
  #
8
- # @param *attributes [Array<Symbol, String>] Instance variable names
9
13
  # @return [nil]
10
14
  #
11
- # @example
15
+ # @raise [ArgumentError] If a predicate method of the same name already exists
16
+ #
17
+ # @example With a regular class
12
18
  # class User
13
- # attr_predicate :admin, :active
19
+ # attr_predicate :admin
20
+ # attr_accessor :admin
14
21
  # end
15
22
  #
16
- # user.admin? # => true/false based on @admin
23
+ # user = User.new
24
+ # user.admin? # => false
25
+ # user.admin = true
26
+ # user.admin? # => true
27
+ #
28
+ # @example With Struct/Data
29
+ # Person = Struct.new(:active)
30
+ # Person.attr_predicate(:active)
31
+ #
32
+ # person = Person.new(active: true)
33
+ # person.active? # => true
17
34
  #
18
35
  def attr_predicate(*attributes)
19
36
  attributes.each do |attribute|
20
- module_eval <<-STR, __FILE__, __LINE__ + 1
37
+ if method_defined?(:"#{attribute}?")
38
+ raise ArgumentError, "Cannot create predicate method on #{self.class} - #{attribute}? is already defined. Please choose a different name or remove the existing method."
39
+ end
40
+
41
+ module_eval <<-RUBY, __FILE__, __LINE__ + 1
21
42
  def #{attribute}?
22
- !!instance_variable_get("@#{attribute}")
43
+ value =
44
+ if instance_variable_defined?(:@#{attribute})
45
+ @#{attribute}
46
+ elsif respond_to?(:#{attribute})
47
+ self.#{attribute}
48
+ end
49
+
50
+ return false if value.nil?
51
+
52
+ defined?(ActiveSupport) ? !!value.presence : !!value
23
53
  end
24
- STR
54
+ RUBY
25
55
  end
26
56
 
27
57
  nil
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Everythingrb
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
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.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 1980-01-01 00:00:00.000000000 Z
11
+ date: 2025-02-11 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.1
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.1
26
+ version: '0.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: json
29
29
  requirement: !ruby/object:Gem::Requirement