seq_as_enum 0.1.0 → 0.3.0

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: 19a14a4dcc30167b2d7577d1dab343571f8e48ad77c1ec5db2b8f3906a1becd6
4
- data.tar.gz: cb35ee9aaa2fd4a738ea1d198c878b07e9b75799a2b92c7e27f824a6035e7163
3
+ metadata.gz: c45de2e91439203353c8e6362ccf4becd6859946609ecc814b09a08045589a43
4
+ data.tar.gz: c034f84fc7e80ad7e0666ebcc82f4ad789a8b7c8f4d9b885412aaa587ca731ff
5
5
  SHA512:
6
- metadata.gz: d05e62eb3d8714bfee09fd238de2e04690cfeb3de056bd280548852e41453df197826424d2bc1bcd718c0ccd551ff416987a17fac9f7572a1c5f7e138a194ec1
7
- data.tar.gz: 05c96a6376f2a658c869c77ecf2bfc96c1a2acfed4d4c46e3710fa3f45b192ca300d0fd289cdf94fde76daa011dbe3df20f8ac4c847e68e8319657de16e64011
6
+ metadata.gz: b2e4836703c9878874a748414fd93d2d393b73644564edee548a0b4c23e7c25987a4b042880f326ad382be88a8107b84bd98a94fe1d46598b29ce3d4d4d39a8d
7
+ data.tar.gz: 76ecfebf9feb146995e34d9fbb1c03eb75214541137af348d4fa2899ad487fbb348657c132a857a2d477c29951d62f83fad2e29b4aa81322b1ccf6c24eeb1aa6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0] - 2023-06-06
4
+
5
+ - Allow override constant
6
+
7
+ ## [0.2.0] - 2023-06-06
8
+
9
+ - Use Struct instead of Data for Ruby 3.1.x and 3.0.x environments.
10
+
3
11
  ## [0.1.0] - 2023-06-06
4
12
 
5
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.0)
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,6 +123,8 @@ class AwesomeCsv
123
123
  end
124
124
  ```
125
125
 
126
+ NOTE: If you're using Ruby 3.1.x or 3.0.x, data_as will use Struct instead of Data.
127
+
126
128
  ## Development
127
129
 
128
130
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -131,7 +133,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
131
133
 
132
134
  ## Contributing
133
135
 
134
- 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).
135
137
 
136
138
  ## License
137
139
 
@@ -139,4 +141,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
139
141
 
140
142
  ## Code of Conduct
141
143
 
142
- 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.1.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/seq_as_enum.rb CHANGED
@@ -5,6 +5,8 @@ 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
@@ -14,23 +16,16 @@ module SeqAsEnum
14
16
 
15
17
  if data_as
16
18
  class_name = "#{data_as}Data"
17
- data_class = Data.define(*names)
18
- const_set!(class_name, data_class)
19
+ data_class = const_defined?(:Data) ? Data.define(*names) : Struct.new(*names, keyword_init: true)
20
+ const_set(class_name, data_class)
19
21
  data = data_class.new(**key_values)
20
- const_set!(data_as, data)
22
+ const_set(data_as, data)
21
23
  else
22
24
  key_values.each do |name, value|
23
25
  sep = '' unless sep
24
26
  name = "#{prefix}#{sep}#{name}".to_sym if prefix
25
- const_set!(name, value)
27
+ const_set(name, value)
26
28
  end
27
29
  end
28
30
  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
31
  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.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Junichi Ito
@@ -10,7 +10,7 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2023-06-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Provide enum like sequences as constants or Data object.
13
+ description: Provide enum like sequences as constants.
14
14
  email:
15
15
  - me@jnito.com
16
16
  executables: []
@@ -45,15 +45,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - ">="
47
47
  - !ruby/object:Gem::Version
48
- version: 3.2.0
48
+ version: 3.0.0
49
49
  required_rubygems_version: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  requirements: []
55
- rubygems_version: 3.4.1
55
+ rubygems_version: 3.4.10
56
56
  signing_key:
57
57
  specification_version: 4
58
- summary: Provide enum like sequences as constants or Data object.
58
+ summary: Provide enum like sequences as constants.
59
59
  test_files: []