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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 329c035e5c90f7cd2c444c1237f2c1c5bf00b50ae6cefcf6f8658c1cdda7fe45
4
- data.tar.gz: debf948e5a235157517ef21d67c6d498f3d2a623cfc9cbe384ae7d81dc8ed05f
3
+ metadata.gz: 7af81ba9c87a0967dd073af1af9efc89281f328f47e44c5d4677d7ae0074fdfa
4
+ data.tar.gz: e53b25152bbdda6c3b4b1acea36d123abae2be84e53e3031f42d1a55aae8f6a1
5
5
  SHA512:
6
- metadata.gz: 730bdbbefa4291935287eda1f56d78cf5f4e4c349426caf4fc20597fdb2cf43d1a627300031a45716dc57b7ecd60c4453de7ee9bb47f76341c19d908d4332a36
7
- data.tar.gz: 8b75285fa43d9440d635566104d5201f8a8192d58d4754c69c134470e8e348456e1b38519aea3b74b9be33fa0a93effd5872566e0d7f2257c86bb5f15c5e16fa
6
+ metadata.gz: e909ed89c6c32d3b6d60219ab5c81de2ae551fe0d4282c631a15f29a12fc4237f7b5be1620c839a25efa2918e8268050ac7fbcb1af4816839c3d1b7596e65ede
7
+ data.tar.gz: '096504aa3169d54cd443e9e29a018cb1bcf8b2f43dc15fe3dca81b103ff17cd4bf4c0c65314c211e920d429c28fd3ee1ea4e2669fabd902128c740227e638ec4'
data/.travis.yml CHANGED
@@ -4,4 +4,6 @@ rvm:
4
4
  - 2.5.3
5
5
  - 2.6.5
6
6
  - 2.7.1
7
+ - 3.0.5
8
+ - 3.1.4
7
9
  before_install: gem install bundler
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
 
@@ -0,0 +1,14 @@
1
+ module YamlEnumeration
2
+ class Configuration
3
+
4
+ DEFAULT_PERMITTED_CLASSED = [].freeze
5
+
6
+ class << self
7
+ attr_writer :permitted_classes
8
+
9
+ def permitted_classes
10
+ @permitted_classes || DEFAULT_PERMITTED_CLASSED
11
+ end
12
+ end
13
+ end
14
+ end
@@ -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(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
@@ -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|
@@ -1,3 +1,3 @@
1
1
  module YamlEnumeration
2
- VERSION = "0.3.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require "yaml_enumeration/version"
2
2
  require "yaml_enumeration/association"
3
3
  require "yaml_enumeration/enumeration"
4
+ require "yaml_enumeration/configuration"
4
5
  require "yaml_enumeration/railtie"
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.3.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: 2022-02-03 00:00:00.000000000 Z
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.2.17
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.