pluckit 1.2.0 → 1.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f0c8e686fd9ed75effb4ce6813bfa337ae81675547b5acacd5c40b2a6596cb69
4
- data.tar.gz: 4dd1015875c89e0a4542e495316e82688cfa0ae64d1f1a67bcc9a040bc41586d
3
+ metadata.gz: 5c607d3a501e2f5bf3a971dc37b53a3088b2f009f4d9d47fbbbca030339de63f
4
+ data.tar.gz: 7f02ef863a371794cade093a6323f08782d493ae6142157b4fdc008b340b173e
5
5
  SHA512:
6
- metadata.gz: f190970663dce56184c3fdd91169899cb4a0db126d4fe543414ea41427d3061169bd131b860c23d617f0b99bd76af5617dcc8d513cb3cdfecc12d25a848c8b93
7
- data.tar.gz: 8eb335b2b94d83a000ab27bc9198dd911736465005cee80134fd8752228b3c6e57ae355170a43f8e0c4be77b8529249ba5d8e2ebcceaf802511fbe09295b43de
6
+ metadata.gz: 434128cd7cf59df1c0ae996b810ba5741775ea0a680a5b7e81d08c663353da3e53975d468fccc2a9e223de3212b9abb72a0d5d7ad9d5843684a6228642338f49
7
+ data.tar.gz: 6acdad5f4a933a5e53464904938172f09820af22ddf5af057dc66a22bc25805ec74bc78b315efe8c5aedc0833ae73b51475c19ab448fbdc553c2f1c4238977ef
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ### 1.3.1 (2026-11-03)
2
+ - fix: `PluckIt.pluck` on other Enumerables (Range, Enumerator, lazy) returns an Array (or a lazy enumerator) instead of raising NoMethodError
3
+ - fix: `PluckIt.pluck` on a frozen Array, Hash, or Set returns a new result instead of raising FrozenError
4
+
5
+ ### 1.3.0 (2026-11-03)
6
+ - drop Ruby 3.0 and 3.1 (end of life); requires Ruby >= 3.2
7
+ - feature: a callable handle (lambda, proc, Method) is called with each value: `users.pluck(->(u) { u.name.upcase })`
8
+
1
9
  ### 1.2.0 (2026-04-11)
2
10
  - ruby and gem updates
3
11
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pluckit (1.2.0)
4
+ pluckit (1.3.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -12,7 +12,7 @@ GEM
12
12
  reline (>= 0.3.8)
13
13
  diff-lcs (1.6.2)
14
14
  docile (1.4.1)
15
- erb (6.0.2)
15
+ erb (6.0.4)
16
16
  io-console (0.8.2)
17
17
  irb (1.17.0)
18
18
  pp (>= 0.6.0)
data/README.md CHANGED
@@ -34,4 +34,23 @@ require 'pluckit'
34
34
  july: 86,
35
35
  august: 80,
36
36
  }
37
+
38
+
39
+ # or pass anything callable
40
+ [ 'alice', 'bob' ].pluck ->(name) { name.capitalize }
41
+ => [ 'Alice', 'Bob' ]
42
+ ```
43
+
44
+
45
+ #### Without the monkey patch
46
+ `require 'pluckit'` adds `#pluck` to Array, Hash, and Set. To skip the global patch, load the module alone and use the refinement, or call it directly:
47
+
48
+ ```ruby
49
+ require 'pluckit/pluck'
50
+
51
+ using PluckIt
52
+ [ { id: 1 } ].pluck :id
53
+
54
+ # or
55
+ PluckIt.pluck [ { id: 1 } ], :id
37
56
  ```
data/lib/pluckit/pluck.rb CHANGED
@@ -20,10 +20,14 @@ module PluckIt
20
20
  end
21
21
 
22
22
  def pluck enumerable, *handles
23
+ # these keep their type (and subclass) via dup.clear; anything else maps
24
+ unless [ Array, Hash, Set ].any? { |klass| enumerable.is_a?(klass) }
25
+ return enumerable.map { |val| pluckit(val, *handles) }
26
+ end
27
+
23
28
  items = enumerable.each_with_object(
24
- enumerable.clone.clear
29
+ enumerable.dup.clear # dup, not clone: clone keeps frozen and singleton methods
25
30
  )
26
- # TODO: if no clone / clear, use new
27
31
 
28
32
  if enumerable.is_a?(Hash)
29
33
  items.each do |(key, val), res|
@@ -51,7 +55,9 @@ module PluckIt
51
55
  private
52
56
 
53
57
  def pluckit_single v, handle
54
- if v.is_a? Hash
58
+ if handle.respond_to?(:call)
59
+ handle.call v
60
+ elsif v.is_a? Hash
55
61
  v[handle]
56
62
  elsif ([Symbol, String].include? handle.class) && v.respond_to?(handle)
57
63
  v.send handle
@@ -1,3 +1,3 @@
1
1
  module PluckIt
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.1'
3
3
  end
data/pluckit.gemspec CHANGED
@@ -1,18 +1,22 @@
1
- package_name = File.basename(__FILE__, '.gemspec')
2
- require_relative File.join('lib', package_name, 'version')
3
- package = PluckIt
1
+ require_relative 'lib/pluckit/version'
4
2
 
5
3
  Gem::Specification.new do |s|
6
4
  s.description = 'Extract values from Enumerables'
7
5
  s.authors = ['Daniel Pepper']
8
6
  s.files = `git ls-files * ':!:spec'`.split("\n")
9
- s.homepage = "https://github.com/dpep/rb_#{package_name}"
7
+ s.homepage = 'https://github.com/dpep/pluckit_rb'
10
8
  s.license = 'MIT'
11
- s.name = package_name
9
+ s.name = 'pluckit'
12
10
  s.summary = 'PluckIt'
13
- s.version = package.const_get('VERSION')
11
+ s.version = PluckIt::VERSION
14
12
 
15
- s.required_ruby_version = '>= 3'
13
+ s.metadata = {
14
+ 'changelog_uri' => "#{s.homepage}/blob/main/CHANGELOG.md",
15
+ 'rubygems_mfa_required' => 'true',
16
+ 'source_code_uri' => s.homepage,
17
+ }
18
+
19
+ s.required_ruby_version = '>= 3.2'
16
20
 
17
21
  s.add_development_dependency 'debug', '>= 1'
18
22
  s.add_development_dependency 'rspec', '>= 3.10'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pluckit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Pepper
@@ -79,10 +79,13 @@ files:
79
79
  - lib/pluckit/pluck.rb
80
80
  - lib/pluckit/version.rb
81
81
  - pluckit.gemspec
82
- homepage: https://github.com/dpep/rb_pluckit
82
+ homepage: https://github.com/dpep/pluckit_rb
83
83
  licenses:
84
84
  - MIT
85
- metadata: {}
85
+ metadata:
86
+ changelog_uri: https://github.com/dpep/pluckit_rb/blob/main/CHANGELOG.md
87
+ rubygems_mfa_required: 'true'
88
+ source_code_uri: https://github.com/dpep/pluckit_rb
86
89
  rdoc_options: []
87
90
  require_paths:
88
91
  - lib
@@ -90,14 +93,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
93
  requirements:
91
94
  - - ">="
92
95
  - !ruby/object:Gem::Version
93
- version: '3'
96
+ version: '3.2'
94
97
  required_rubygems_version: !ruby/object:Gem::Requirement
95
98
  requirements:
96
99
  - - ">="
97
100
  - !ruby/object:Gem::Version
98
101
  version: '0'
99
102
  requirements: []
100
- rubygems_version: 3.6.9
103
+ rubygems_version: 4.0.16
101
104
  specification_version: 4
102
105
  summary: PluckIt
103
106
  test_files: []