yaml_enumeration 0.2.2 → 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: d42b540fe754657e4e982b3324efcc67aaf7726019311dc574ec0035ee7b76ea
4
- data.tar.gz: c046de0c21e60c0f0bed6be8f276b60988182ecb793893ce4433d8cfbccfa1af
3
+ metadata.gz: 329c035e5c90f7cd2c444c1237f2c1c5bf00b50ae6cefcf6f8658c1cdda7fe45
4
+ data.tar.gz: debf948e5a235157517ef21d67c6d498f3d2a623cfc9cbe384ae7d81dc8ed05f
5
5
  SHA512:
6
- metadata.gz: d4b52ee6c9b97391eb0d3aea409595c2d3ef253a7b364222d47020da7fa4e017802029556b50d4e0d997ea08a14f8b2c6d6287d334f0a56d94f874c87fe37974
7
- data.tar.gz: ec4e04994a577354f8fd360601a5f4b07ba3153193a356dac69c8a89b162431451f75dd4addc7477be5cff26fe7cad968481f84ef1b374dd9649b8df744f3fb1
6
+ metadata.gz: 730bdbbefa4291935287eda1f56d78cf5f4e4c349426caf4fc20597fdb2cf43d1a627300031a45716dc57b7ecd60c4453de7ee9bb47f76341c19d908d4332a36
7
+ data.tar.gz: 8b75285fa43d9440d635566104d5201f8a8192d58d4754c69c134470e8e348456e1b38519aea3b74b9be33fa0a93effd5872566e0d7f2257c86bb5f15c5e16fa
data/CHANGELOG.md CHANGED
@@ -1,14 +1,17 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.3.0
4
+ * enable exclusion of blocks of YAML from the enumeration (support YAML anchors) [#6](https://github.com/alto/yaml_enumeration/pull/6)
5
+
3
6
  ## 0.2.2
4
- * enhance find-by methods [#4])(https://github.com/alto/yaml_enumeration/pull/4)
5
- * add support for Ruby `2.6` and `2.7` [#3])(https://github.com/alto/yaml_enumeration/pull/3)
7
+ * enhance find-by methods [#4](https://github.com/alto/yaml_enumeration/pull/4)
8
+ * add support for Ruby `2.6` and `2.7` [#3](https://github.com/alto/yaml_enumeration/pull/3)
6
9
 
7
10
  ## 0.2.1
8
- * add support for Ruby `2.5.3` [#2])(https://github.com/alto/yaml_enumeration/pull/2)
11
+ * add support for Ruby `2.5.3` [#2](https://github.com/alto/yaml_enumeration/pull/2)
9
12
 
10
13
  ## 0.2.0
11
- * support _ActiveRecord_ methods `where`, `find_by` [#1])(https://github.com/alto/yaml_enumeration/pull/1), thanks to [@richdrich](https://github.com/richdrich)
14
+ * support _ActiveRecord_ methods `where`, `find_by` [#1](https://github.com/alto/yaml_enumeration/pull/1), thanks to [@richdrich](https://github.com/richdrich)
12
15
 
13
16
  ## 0.1.0
14
17
  * 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
- YAML.load(ERB.new(File.read(file)).result).values.each do |data|
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
@@ -144,5 +144,10 @@ module YamlEnumeration
144
144
  self.id = id
145
145
  end
146
146
 
147
+ def self.remove_exclusions(result)
148
+ keys_to_remove = result.keys.select {|key| key =~ /.*_exclude_from_enumeration$/ }
149
+ result.except(*keys_to_remove)
150
+ end
151
+
147
152
  end # Enumeration
148
153
  end
@@ -1,3 +1,3 @@
1
1
  module YamlEnumeration
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
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.2.2
4
+ version: 0.3.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: 2021-06-28 00:00:00.000000000 Z
11
+ date: 2022-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler