yaml_enumeration 0.2.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/CHANGELOG.md +10 -4
- data/README.md +30 -0
- data/lib/yaml_enumeration/configuration.rb +14 -0
- data/lib/yaml_enumeration/enumeration.rb +14 -1
- data/lib/yaml_enumeration/version.rb +1 -1
- data/lib/yaml_enumeration.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 789056e38408fc39c5203d9b27347d67eac1223a005c4e97d6c3fbb0b50e52c9
|
4
|
+
data.tar.gz: f687bbcc331fa6959225a5701721b156ae652dc5c51540f4a85d2b8c75d66ab0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 937de680ad7a668d42faa880eac779d53d0bfb9833bfdf981f50c97cf3703d113de49e550b3290ae27c9a7ca7173d44b0630cbf5922a07e60464b98886cb20e5
|
7
|
+
data.tar.gz: bc24da29146aac8453d17badffaf83176dc8c937d54eff3660ead43b8261237445741c1db95fff163bdf8f0fddeb80adc6e2f925573f3aa2d71604a4c05b3b8d
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,14 +1,20 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 0.4.0
|
4
|
+
* add support for Ruby `3.1` [#7](https://github.com/alto/yaml_enumeration/pull/7)
|
5
|
+
|
6
|
+
## 0.3.0
|
7
|
+
* enable exclusion of blocks of YAML from the enumeration (support YAML anchors) [#6](https://github.com/alto/yaml_enumeration/pull/6)
|
8
|
+
|
3
9
|
## 0.2.2
|
4
|
-
* enhance find-by methods [#4]
|
5
|
-
* add support for Ruby `2.6` and `2.7` [#3]
|
10
|
+
* enhance find-by methods [#4](https://github.com/alto/yaml_enumeration/pull/4)
|
11
|
+
* add support for Ruby `2.6` and `2.7` [#3](https://github.com/alto/yaml_enumeration/pull/3)
|
6
12
|
|
7
13
|
## 0.2.1
|
8
|
-
* add support for Ruby `2.5.3` [#2]
|
14
|
+
* add support for Ruby `2.5.3` [#2](https://github.com/alto/yaml_enumeration/pull/2)
|
9
15
|
|
10
16
|
## 0.2.0
|
11
|
-
* support _ActiveRecord_ methods `where`, `find_by` [#1]
|
17
|
+
* support _ActiveRecord_ methods `where`, `find_by` [#1](https://github.com/alto/yaml_enumeration/pull/1), thanks to [@richdrich](https://github.com/richdrich)
|
12
18
|
|
13
19
|
## 0.1.0
|
14
20
|
* initial version
|
data/README.md
CHANGED
@@ -80,6 +80,36 @@ class User < ActiveRecord::Base
|
|
80
80
|
end
|
81
81
|
```
|
82
82
|
|
83
|
+
additional `yaml` syntax such as anchors can be removed from the enumeration by including `_exclude_from_enumeration`:
|
84
|
+
|
85
|
+
```yaml
|
86
|
+
# countries.yml
|
87
|
+
---
|
88
|
+
defaults_exclude_from_enumeration: &defaults
|
89
|
+
continent: Australia
|
90
|
+
|
91
|
+
nz:
|
92
|
+
<<: *defaults
|
93
|
+
id: 1 # has to be provided
|
94
|
+
type: new_zealand # has to be provided
|
95
|
+
name: New Zealand
|
96
|
+
code: nz
|
97
|
+
au:
|
98
|
+
<<: *defaults
|
99
|
+
id: 2
|
100
|
+
type: australia
|
101
|
+
name: Australia
|
102
|
+
code: au
|
103
|
+
uk:
|
104
|
+
<<: *defaults
|
105
|
+
id: 3
|
106
|
+
type: united_kingdom
|
107
|
+
name: United Kingdom
|
108
|
+
code: uk
|
109
|
+
continent: Europe
|
110
|
+
...
|
111
|
+
```
|
112
|
+
|
83
113
|
## Accessing members
|
84
114
|
|
85
115
|
If you include a call to class method `with_named_items` you will get an item defined for each typed entry in the enumeration, e.g. `Country.NEW_ZEALAND` and `Country.AUSTRALIA`.
|
@@ -13,7 +13,7 @@ module YamlEnumeration
|
|
13
13
|
|
14
14
|
def self.load_values(filename)
|
15
15
|
file = File.join(Rails.root, 'db', 'enumerations', "#{filename}.yml")
|
16
|
-
|
16
|
+
remove_exclusions(yaml_load(ERB.new(File.read(file)).result)).values.each do |data|
|
17
17
|
value data.symbolize_keys
|
18
18
|
end
|
19
19
|
end
|
@@ -126,6 +126,14 @@ module YamlEnumeration
|
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
|
+
def yaml_load(source)
|
130
|
+
begin
|
131
|
+
YAML.load(source, aliases: true, permitted_classes: Configuration.permitted_classes)
|
132
|
+
rescue ArgumentError
|
133
|
+
YAML.load(source, permitted_classes: Configuration.permiitted_classes)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
129
137
|
# Define singleton methods .BLAH for each type
|
130
138
|
def with_named_items(column = :type)
|
131
139
|
all.each do |item|
|
@@ -144,5 +152,10 @@ module YamlEnumeration
|
|
144
152
|
self.id = id
|
145
153
|
end
|
146
154
|
|
155
|
+
def self.remove_exclusions(result)
|
156
|
+
keys_to_remove = result.keys.select {|key| key =~ /.*_exclude_from_enumeration$/ }
|
157
|
+
result.except(*keys_to_remove)
|
158
|
+
end
|
159
|
+
|
147
160
|
end # Enumeration
|
148
161
|
end
|
data/lib/yaml_enumeration.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaml_enumeration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thorsten Boettger
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- bin/setup
|
116
116
|
- lib/yaml_enumeration.rb
|
117
117
|
- lib/yaml_enumeration/association.rb
|
118
|
+
- lib/yaml_enumeration/configuration.rb
|
118
119
|
- lib/yaml_enumeration/enumeration.rb
|
119
120
|
- lib/yaml_enumeration/railtie.rb
|
120
121
|
- lib/yaml_enumeration/version.rb
|
@@ -138,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
139
|
- !ruby/object:Gem::Version
|
139
140
|
version: '0'
|
140
141
|
requirements: []
|
141
|
-
rubygems_version: 3.
|
142
|
+
rubygems_version: 3.3.26
|
142
143
|
signing_key:
|
143
144
|
specification_version: 4
|
144
145
|
summary: Create ActiveRecord enumerations based on YAML files.
|