humanize_enum 0.1.9 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d6163c9c0cc6895cda69e255abc7c953814c863e76300d70b2916c8e2b245eb
4
- data.tar.gz: da44277aabc9a034de3090b5f202ff49339d68b71d0213714b7c7254e2f45208
3
+ metadata.gz: e87b96ee4668b93f22c2bc46b9875370731950ade9a93fc7f8bb39430eb6b442
4
+ data.tar.gz: 9a68e4e3fcb1bcfb1c053ea737dc4e9e8eeed78644a786850f042fe874c10d29
5
5
  SHA512:
6
- metadata.gz: dbc0ce238f10c8215b7555aa964d5f5611bfb8133eb521ebb98ed3c3c66641c402d25aa222877bfe85d4c94e79be272f06f19963cb4c9ce65ccfb56a0d6d8898
7
- data.tar.gz: 6815ee75ea944d1c6df5cfde200d5c7190d852898eb2ea79e1b071b74069e88e62a37cd22db0d5e3439b9e0fcd85c400c08422def32c63d5a222c062c292dcd8
6
+ metadata.gz: 57553ef0eb58356028d0a5b9d4b7883284e80e1a06ea09cbface928763875df9ffa10141d94315a7f1419d9f4e3973df4495fc730ec210d79993061238344529
7
+ data.tar.gz: 3c3deb9f52281157c34dc207c5355b1eb90d2cf864ea865a8e145bc2bb9cf717bda7c3a7591628d083b988df7b99e4ac994bd376ed3fa26eb8392d27a2548d3e
data/README.md CHANGED
@@ -151,6 +151,18 @@ Document.dehumanize_enum(:documentable_type, 'Article') # => :article
151
151
  ```
152
152
 
153
153
 
154
+ ### Configuration
155
+
156
+ Before using `humanize_enum`, you should ensure it has been configured properly. Specifically, the `check_defined_enums` option should be set to `false` if you plan to use `humanize_enum` with polymorphic association types.
157
+ ```ruby
158
+ # config/initializers/humanize_enum.rb
159
+ HumanizeEnum.configure do |config|
160
+ config.check_defined_enums = false
161
+ end
162
+ ```
163
+ In absence of this configuration, humanize_enum would attempt to verify if the provided attribute is a defined enum, which is not what you want when working with polymorphic types. By default, `check_defined_enums` is true.
164
+
165
+
154
166
  ## Inspired by
155
167
 
156
168
  - a post by [Juraj Kostolanský](https://www.kostolansky.sk/posts/localize-rails-enums/) and
@@ -49,6 +49,7 @@ module HumanizeEnum
49
49
  # @param enum_name [String, Symbol]
50
50
  # @raise [UnknownEnumKey] if enum_name is not a defined enum
51
51
  def check_enum!(enum_name)
52
+ return unless HumanizeEnum.configuration.check_defined_enums
52
53
  raise UnknownEnumKey unless defined_enums.has_key?(enum_name.to_s)
53
54
  end
54
55
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HumanizeEnum
4
- VERSION = '0.1.9'
4
+ VERSION = '0.1.10'
5
5
  end
data/lib/humanize_enum.rb CHANGED
@@ -7,6 +7,25 @@ require 'active_support/lazy_load_hooks'
7
7
  require 'active_support/inflector'
8
8
 
9
9
  module HumanizeEnum
10
+ class Configuration
11
+ attr_accessor :check_defined_enums
12
+
13
+ def initialize
14
+ @check_defined_enums = true
15
+ end
16
+ end
17
+
18
+ class << self
19
+ def configuration
20
+ @configuration ||= Configuration.new
21
+ end
22
+ end
23
+
24
+ # create configure class method to yield the config class
25
+ def self.configure
26
+ self.configuration ||= Configuration.new
27
+ yield(configuration)
28
+ end
10
29
 
11
30
  # Error for an unknown enum key
12
31
  UnknownEnumKey = Class.new(StandardError)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: humanize_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Buslaev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-21 00:00:00.000000000 Z
11
+ date: 2024-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport