seq_as_enum 0.1.0 → 0.3.0
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 +4 -4
- data/CHANGELOG.md +8 -0
- data/CODE_OF_CONDUCT.md +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +5 -3
- data/lib/seq_as_enum/version.rb +1 -1
- data/lib/seq_as_enum.rb +6 -11
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c45de2e91439203353c8e6362ccf4becd6859946609ecc814b09a08045589a43
|
4
|
+
data.tar.gz: c034f84fc7e80ad7e0666ebcc82f4ad789a8b7c8f4d9b885412aaa587ca731ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2e4836703c9878874a748414fd93d2d393b73644564edee548a0b4c23e7c25987a4b042880f326ad382be88a8107b84bd98a94fe1d46598b29ce3d4d4d39a8d
|
7
|
+
data.tar.gz: 76ecfebf9feb146995e34d9fbb1c03eb75214541137af348d4fa2899ad487fbb348657c132a857a2d477c29951d62f83fad2e29b4aa81322b1ccf6c24eeb1aa6
|
data/CHANGELOG.md
CHANGED
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
|
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
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
|
-
|
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/
|
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/
|
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).
|
data/lib/seq_as_enum/version.rb
CHANGED
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
|
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
|
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
|
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.
|
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
|
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.
|
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.
|
55
|
+
rubygems_version: 3.4.10
|
56
56
|
signing_key:
|
57
57
|
specification_version: 4
|
58
|
-
summary: Provide enum like sequences as constants
|
58
|
+
summary: Provide enum like sequences as constants.
|
59
59
|
test_files: []
|