seq_as_enum 0.2.0 → 0.3.1

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: 6ed043cc3fc1e665375938158a59ea4f383fdd950c92c9ed1dd83eee62955efd
4
- data.tar.gz: 99db0b6e544984f67a1fb47fcad0a08bcb15f0461b07200b65f6bfd5093b3c79
3
+ metadata.gz: ba23f53815d973ccafa1128b109205e7070d8e5f2a372027d0d8bf4ce6405c7d
4
+ data.tar.gz: b52fa40d67395b1d08b10ad1f121ed216dc41ca3ee5bf3e6c8ae9e11660f3b3d
5
5
  SHA512:
6
- metadata.gz: acc00518b38c8be7670fdc9b1d6ed6ab9e066099a04dd04e1723649ded370269752d8499e7138e81201a310b5d6f9668a691048e1303c7c9f07d48b06a5c8594
7
- data.tar.gz: 1ab81b07529fcd49895fed3a21d57f4d74b118aadfc5a8d008043047278ccbf015c4b9278917f651179a49da4f5736855c896d4887a9374afb576c1246f6b272
6
+ metadata.gz: 7621dabeb62441e2ecb77c1c04f66f239e5d0c71238ce61241197242211656259711a55fe48dfc16e23c0b973034e3c6f8a546926ef4ee882c48ed8335c1b0b7
7
+ data.tar.gz: c933ee7589eef1760d0c198ccde85b0740d9400ce9277d0fc320e3a56b21afa1f913f72df000f14c1868b27259345a5fa13039cd021b8e985861eda7f6134258
data/CHANGELOG.md CHANGED
@@ -1,7 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.1] - 2023-06-07
4
+ - Avoid defining data class as constant
5
+
6
+ ## [0.3.0] - 2023-06-06
7
+ - Allow override constant
8
+
9
+ ## [0.2.0] - 2023-06-06
3
10
  - Use Struct instead of Data for Ruby 3.1.x and 3.0.x environments.
4
11
 
5
12
  ## [0.1.0] - 2023-06-06
6
-
7
13
  - Initial release
data/CODE_OF_CONDUCT.md CHANGED
@@ -39,7 +39,7 @@ This Code of Conduct applies within all community spaces, and also applies when
39
39
 
40
40
  ## Enforcement
41
41
 
42
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at jit@sonicgarden.jp. All complaints will be reviewed and investigated promptly and fairly.
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at JunichiIto. All complaints will be reviewed and investigated promptly and fairly.
43
43
 
44
44
  All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
45
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- seq_as_enum (0.1.0)
4
+ seq_as_enum (0.3.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -97,7 +97,7 @@ seq_as_enum :Name, :Address, :Phone, prefix: :Col, sep: false
97
97
 
98
98
  ### data_as option
99
99
 
100
- You can get sequence values as Data object instead of constants:
100
+ With `data_as` option, you can get sequence values as Data object instead of constants:
101
101
 
102
102
  ```ruby
103
103
  class AwesomeCsv
@@ -123,7 +123,7 @@ class AwesomeCsv
123
123
  end
124
124
  ```
125
125
 
126
- NOTE: If you use Ruby 3.1.x or 3.0.x, data_as will use Struct instead of Data.
126
+ NOTE: If you're using Ruby 3.1.x or 3.0.x, data_as will use Struct instead of Data.
127
127
 
128
128
  ## Development
129
129
 
@@ -133,7 +133,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
133
133
 
134
134
  ## Contributing
135
135
 
136
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/seq_as_enum. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/seq_as_enum/blob/main/CODE_OF_CONDUCT.md).
136
+ Bug reports and pull requests are welcome on GitHub at https://github.com/JunichiIto/seq_as_enum. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/JunichiIto/seq_as_enum/blob/main/CODE_OF_CONDUCT.md).
137
137
 
138
138
  ## License
139
139
 
@@ -141,4 +141,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
141
141
 
142
142
  ## Code of Conduct
143
143
 
144
- Everyone interacting in the SeqAsEnum project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/seq_as_enum/blob/main/CODE_OF_CONDUCT.md).
144
+ Everyone interacting in the SeqAsEnum project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/JunichiIto/seq_as_enum/blob/main/CODE_OF_CONDUCT.md).
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SeqAsEnum
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.1"
5
5
  end
data/lib/seq_as_enum.rb CHANGED
@@ -5,32 +5,24 @@ require_relative "seq_as_enum/version"
5
5
  module SeqAsEnum
6
6
  DEFAULT_SEP = '_'.freeze
7
7
 
8
+ private
9
+
8
10
  def seq_as_enum(*names, init: 0, data_as: nil, prefix: nil, sep: DEFAULT_SEP)
9
11
  raise ArgumentError, 'Cannot use prefix option with data_as option' if prefix && data_as
10
12
  raise ArgumentError, 'Cannot use sep option without prefix option' if sep != DEFAULT_SEP && !prefix
11
13
 
12
- counter = init
13
- key_values = names.to_h { |name| [name, counter].tap { counter = counter.succ } }
14
+ key_values = names.zip(Enumerator.produce(init, &:succ)).to_h
14
15
 
15
16
  if data_as
16
- class_name = "#{data_as}Data"
17
17
  data_class = const_defined?(:Data) ? Data.define(*names) : Struct.new(*names, keyword_init: true)
18
- const_set!(class_name, data_class)
19
18
  data = data_class.new(**key_values)
20
- const_set!(data_as, data)
19
+ const_set(data_as, data)
21
20
  else
22
21
  key_values.each do |name, value|
23
22
  sep = '' unless sep
24
23
  name = "#{prefix}#{sep}#{name}".to_sym if prefix
25
- const_set!(name, value)
24
+ const_set(name, value)
26
25
  end
27
26
  end
28
27
  end
29
-
30
- private
31
-
32
- def const_set!(sym, obj)
33
- raise "already initialized constant: #{self.name}::#{sym}" if const_defined?(sym)
34
- const_set(sym, obj)
35
- end
36
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seq_as_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Junichi Ito
@@ -52,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  requirements: []
55
- rubygems_version: 3.4.10
55
+ rubygems_version: 3.4.1
56
56
  signing_key:
57
57
  specification_version: 4
58
58
  summary: Provide enum like sequences as constants.