yaml_enumeration 0.3.0 → 0.5.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 +6 -0
- data/lib/yaml_enumeration/configuration.rb +14 -0
- data/lib/yaml_enumeration/enumeration.rb +24 -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: 7af81ba9c87a0967dd073af1af9efc89281f328f47e44c5d4677d7ae0074fdfa
|
4
|
+
data.tar.gz: e53b25152bbdda6c3b4b1acea36d123abae2be84e53e3031f42d1a55aae8f6a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e909ed89c6c32d3b6d60219ab5c81de2ae551fe0d4282c631a15f29a12fc4237f7b5be1620c839a25efa2918e8268050ac7fbcb1af4816839c3d1b7596e65ede
|
7
|
+
data.tar.gz: '096504aa3169d54cd443e9e29a018cb1bcf8b2f43dc15fe3dca81b103ff17cd4bf4c0c65314c211e920d429c28fd3ee1ea4e2669fabd902128c740227e638ec4'
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 0.5.0
|
4
|
+
* introduce `count`, `first` and `last` methods [#8](https://github.com/alto/yaml_enumeration/pull/8)
|
5
|
+
|
6
|
+
## 0.4.0
|
7
|
+
* add support for Ruby `3.1` [#7](https://github.com/alto/yaml_enumeration/pull/7)
|
8
|
+
|
3
9
|
## 0.3.0
|
4
10
|
* enable exclusion of blocks of YAML from the enumeration (support YAML anchors) [#6](https://github.com/alto/yaml_enumeration/pull/6)
|
5
11
|
|
@@ -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
|
-
remove_exclusions(
|
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
|
@@ -78,6 +78,21 @@ module YamlEnumeration
|
|
78
78
|
self.all_instances ||= values.keys.map {|id| new(id)}
|
79
79
|
end
|
80
80
|
|
81
|
+
def count
|
82
|
+
return 0 unless values
|
83
|
+
all.size
|
84
|
+
end
|
85
|
+
|
86
|
+
def first
|
87
|
+
return nil unless values
|
88
|
+
all.first
|
89
|
+
end
|
90
|
+
|
91
|
+
def last
|
92
|
+
return nil unless values
|
93
|
+
all.last
|
94
|
+
end
|
95
|
+
|
81
96
|
def find(id)
|
82
97
|
case id
|
83
98
|
when Integer
|
@@ -126,6 +141,14 @@ module YamlEnumeration
|
|
126
141
|
end
|
127
142
|
end
|
128
143
|
|
144
|
+
def yaml_load(source)
|
145
|
+
begin
|
146
|
+
YAML.load(source, aliases: true, permitted_classes: Configuration.permitted_classes)
|
147
|
+
rescue ArgumentError
|
148
|
+
YAML.load(source, permitted_classes: Configuration.permiitted_classes)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
129
152
|
# Define singleton methods .BLAH for each type
|
130
153
|
def with_named_items(column = :type)
|
131
154
|
all.each do |item|
|
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.5.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-10-30 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.
|