seq_as_enum 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/CODE_OF_CONDUCT.md +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +4 -4
- data/lib/seq_as_enum/version.rb +1 -1
- data/lib/seq_as_enum.rb +5 -10
- metadata +1 -1
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,7 +123,7 @@ class AwesomeCsv
|
|
123
123
|
end
|
124
124
|
```
|
125
125
|
|
126
|
-
NOTE: If you
|
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/
|
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/
|
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
|
@@ -15,22 +17,15 @@ module SeqAsEnum
|
|
15
17
|
if data_as
|
16
18
|
class_name = "#{data_as}Data"
|
17
19
|
data_class = const_defined?(:Data) ? Data.define(*names) : Struct.new(*names, keyword_init: true)
|
18
|
-
const_set
|
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
|