trinkets 0.3.0 → 0.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: '018b1a7eeedc27c57853bd408ac7b698f1573f7b2646c7fdb8f36e2dce2b0add'
4
- data.tar.gz: 50d9ec8927e0f127c17a410148c923e382b2749afe5ba87f13ef6d518349ecd4
3
+ metadata.gz: cb82b9c6f72cce48f7d303e989870bc05e77429508c17f266428d15bc0821628
4
+ data.tar.gz: 1dc0a8334a869e8be5b4e397caeed6be9ff16b495514425e184938d538b0b2e1
5
5
  SHA512:
6
- metadata.gz: 73b50ad1d15f661512a2c1b230b993b6d4a9a56d5a8a72ebc9a7cd9cfe03989bd32897131f1991a071daaac50fdad2eaf8fb0cbfd4dd60430ea6de74c3cddbcc
7
- data.tar.gz: 8643d7e712ef9798b459cb9dc28f35e72f4dc80215e2b860c7a23a06a4c029dac83d7271324f2605d6812d30c40ad96032d348fca2c1eeb62812c7923666e81f
6
+ metadata.gz: 4b57aecbcc07de7c710804302accad6fe49d610c133fabf74040a0cca376129258dc064eb967c0ff50570d72b46d641160fda6485222d29f47f06117b57db55c
7
+ data.tar.gz: 7714dbbd7e295d87d9f6c98aac8d6aade0d6a57d86e69368c039e8022824511f897f1a2d8f90f5f70b1fb598741b4bfbfdbb5308a164f40dc2fcb6da01491148
data/CHANGELOG.md CHANGED
@@ -1,4 +1,7 @@
1
1
 
2
+ ### [0.3.1](https://github.com/SilverPhoenix99/trinkets/tree/v0.3.1)
3
+ * Fixed repeated arguments in `Class::init`.
4
+
2
5
  ### [0.3.0](https://github.com/SilverPhoenix99/trinkets/tree/v0.3.0)
3
6
  * Restructured folders to default to `/refine/`.
4
7
  * Added `Enumerable#each_with_hash`/`Enumerator#with_hash`.
data/README.md CHANGED
@@ -4,10 +4,16 @@ It's the bootleg [facets](https://github.com/rubyworks/facets?tab=readme-ov-file
4
4
 
5
5
  ## Installation
6
6
 
7
+ ### RubyGems
7
8
  ```
8
9
  gem install trinkets
9
10
  ```
10
11
 
12
+ ### Bundler
13
+ ```ruby
14
+ gem 'trinkets', require: false
15
+ ```
16
+
11
17
  ## Usage
12
18
 
13
19
  The trinkets are loaded with the following structure:
@@ -34,7 +40,7 @@ The `refine` subdirectory is the default, and it can be omitted from `require`.
34
40
  require 'trinkets/refine/class/init'
35
41
  ```
36
42
 
37
- ### Extend
43
+ ### Extend / Include
38
44
 
39
45
  ```ruby
40
46
  require 'trinkets/extend/class/init'
@@ -44,6 +50,15 @@ class Test
44
50
  end
45
51
  ```
46
52
 
53
+ ```ruby
54
+ require 'trinkets/include/enumerable/each_with_hash'
55
+
56
+ class Test
57
+ include Enumerable
58
+ include ::Trinkets::Enumerable::WithHash
59
+ end
60
+ ```
61
+
47
62
  ### Mokey Patching
48
63
 
49
64
  ```ruby
@@ -11,16 +11,7 @@ module Trinkets
11
11
 
12
12
  default_attr_options = { attr: attr, kw: kw }
13
13
 
14
- # Normalize attrs into a hash: { :name => **options }
15
- # @type [Hash[Symbol, Hash]]
16
- attrs = attrs.map { |a| [*a] }
17
- .map { |a| a.size == 1 ? a << {} : a }
18
- .each_with_object({}) do |(name, opts), h|
19
- # name, opts = a
20
- name = name.to_s.sub(/^@/, '').to_sym
21
- opts = default_attr_options.merge(opts)
22
- h[name] = opts
23
- end
14
+ attrs = ::Trinkets::Class.send(:sanitize_attrs, attrs, default_attr_options)
24
15
 
25
16
  attr_methods = (ATTR - [:none])
26
17
  .each_with_object({}) do |name, h|
@@ -43,12 +34,32 @@ module Trinkets
43
34
  .partition { |_, kw_opt| kw_opt }
44
35
  .map(&:to_h)
45
36
 
46
- init_method = ::Trinkets::Class.send :define_initialize, attrs, kw_attrs
37
+ init_method = ::Trinkets::Class.send(:define_initialize, attrs, kw_attrs)
47
38
  define_method :initialize, init_method
48
39
  end
49
40
  end
50
41
 
51
42
  class << self
43
+ private def sanitize_attrs(attrs, default_attr_options)
44
+ # Normalize attrs into an array: [[:name, **options], ...]
45
+ # @type [Array[Array[Symbol, Hash]]]
46
+ attrs = attrs.map do |a|
47
+ name, opts = [*a]
48
+ name = name.to_s.sub(/^@/, '').to_sym
49
+ opts = default_attr_options.merge(opts || {})
50
+ [name, opts]
51
+ end
52
+
53
+ repeated_attrs = attrs.map(&:first)
54
+ .tally
55
+ .select { |_, count| count > 1 }
56
+ .keys
57
+
58
+ raise ArgumentError, "duplicated argument names: #{repeated_attrs.join(', ')}" if repeated_attrs.any?
59
+
60
+ attrs.to_h
61
+ end
62
+
52
63
  # @param [Hash[Symbol Boolean]] attrs
53
64
  # @param [Hash[Symbol Boolean]] kw_attrs
54
65
  private def define_initialize(attrs, kw_attrs)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Trinkets
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trinkets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - SilverPhoenix99
@@ -9,8 +9,36 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-02-03 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2024-02-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '3.0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '3.0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: simplecov
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 0.22.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.22.0
14
42
  description: Truly outrageous bootleg facets in your trinkets box.
15
43
  email:
16
44
  - antoniopedrosilvapinto@gmail.com
@@ -38,6 +66,10 @@ licenses:
38
66
  - MIT
39
67
  metadata:
40
68
  homepage_uri: https://github.com/SilverPhoenix99/trinkets
69
+ source_code_uri: https://github.com/SilverPhoenix99/trinkets
70
+ changelog_uri: https://github.com/SilverPhoenix99/trinkets/blob/master/CHANGELOG.md
71
+ bug_tracker_uri: https://github.com/SilverPhoenix99/trinkets/issues
72
+ documentation_uri: https://github.com/SilverPhoenix99/trinkets/blob/master/README.md
41
73
  post_install_message:
42
74
  rdoc_options: []
43
75
  require_paths: