enum_ext 0.9.0 → 1.0.0.rc

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: efd427aa71da1e4f38c9ee7837d170ef9732a709dc23a80332d7d61456632350
4
- data.tar.gz: 42e2acb52324970fb199cf036c5763f7c4d4c8ce5e7fdd8c7fca80dc08913807
3
+ metadata.gz: 13e0504e5a07f15d1d1308cce427cc3521520d76f8e61298c8c46568e1d3c9d4
4
+ data.tar.gz: 869bab9d23901292cb977f62cc79e0ab9e760851cb05c8b9596a334457e99977
5
5
  SHA512:
6
- metadata.gz: 3c1aaf8307cba00ba948a79f2ceee1acd09dd1b310c9ee22c892c5e776d63716addcb3e2f3c505146b98c206fdc9f8134309a58b268c323e7df697f380221650
7
- data.tar.gz: e7ea79641953c863d45427c3a5eca6a942089a9cfb1f796ddc54a0fd5dbb275ca598d172d03f61ded14e5a5751c6cdca44423053c3acfb1ecdf3d87db542fa68
6
+ metadata.gz: 27c879c403dcd5d2328bca485426e58063c9ca3a396b6255cd5d3c2bddb96edbb2522f37499084152a6dcea23915c45b64633e78d2284ac769e14a1c5b9cdb00
7
+ data.tar.gz: 1dcc91a044f65445593cf8be10c29e49e06a99d756233f50d2b41c7c737100eea10061a08ff28915e8564e881f047afc6e3709b7e7d4a49b3fd2d3ccc65d3a6c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 1.0.0.rc
2
+ * global configuration added
3
+
4
+ # 0.9.1
5
+ * fix https://github.com/alekseyl/enum_ext/issues/53
6
+
1
7
  # 0.9
2
8
  * supersets works fine and same way with prefixes and suffixes as usual enum does
3
9
 
data/README.md CHANGED
@@ -320,6 +320,20 @@ And per extension methods (describe_enum_i, e.t.c)
320
320
  ```
321
321
  ![img_3.png](img_3.png)
322
322
 
323
+ ## Configuration
324
+ ```ruby
325
+ EnumExt.configure do |config|
326
+ # the name of class which will have EnumExt extended globally
327
+ # default: nil
328
+ config.application_record_class = ApplicationRecord
329
+ # default helpers, will be added to every enum ext definitions
330
+ # default value: [:multi_enum_scopes, :mass_assign_enum]
331
+ config.default_helpers = [:multi_enum_scopes, :mass_assign_enum]
332
+ end
333
+
334
+ ```
335
+
336
+
323
337
  ## Tests
324
338
  Starting version 0.6 added support for rails 7+ enum definitions, that's making testing a little bit not that easy as running `rake test`.
325
339
  Now testings are done via `docker-compose up`. Look closer to Dockerfiles and `docker-compose.yml`
@@ -334,7 +348,6 @@ rake test TEST=test/test_enum_ext.rb TESTOPTS="--name=/bb/"
334
348
  ## Development
335
349
 
336
350
  ## TODO
337
- [] better support for suffix/prefix as enum does
338
351
  [] add global config and allow global extension
339
352
 
340
353
  ## Contributing
@@ -8,7 +8,7 @@ module EnumExt::BasicHelpers
8
8
  #
9
9
  # Rem. Will not define helper when enum values are strings, and will print warning
10
10
  def enum_i( enum_name )
11
- return puts(<<~NOTINTEGER) if columns_hash[enum_name.to_s].type != :integer
11
+ return puts(<<~NOTINTEGER) if table_exists? && columns_hash[enum_name.to_s].type != :integer
12
12
  ---------------------NOTINTEGER WARNING!---------------------------
13
13
  #{enum_name} is not an integer column, so enum_i helper useless and method will not be defined
14
14
  NOTINTEGER
@@ -0,0 +1,20 @@
1
+ module EnumExt
2
+ class EnumExtConfig
3
+ attr_accessor :default_helpers, :application_record_class
4
+
5
+ def initialize
6
+ self.default_helpers = [:multi_enum_scopes, :mass_assign_enum]
7
+ end
8
+ end
9
+
10
+ class << self
11
+ def configure
12
+ yield(config)
13
+ config.application_record_class&.extend( EnumExt ) if config.application_record_class.is_a?(Class)
14
+ end
15
+
16
+ def config
17
+ @config ||= EnumExtConfig.new
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module EnumExt
2
- VERSION = "0.9.0"
2
+ VERSION = "1.0.0.rc"
3
3
  end
data/lib/enum_ext.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "enum_ext/version"
2
+ require "enum_ext/config"
2
3
  require "enum_ext/annotated"
3
4
  require "enum_ext/enum_wrapper"
4
5
  require "enum_ext/humanize_helpers"
@@ -16,24 +17,6 @@ require "enum_ext/superset_helpers"
16
17
  # has_many :requests
17
18
  # end
18
19
 
19
- puts <<~DEPRECATION
20
- ---------------------DEPRECATION WARNING---------------------------
21
- There are TWO MAJOR breaking changes coming into the next major version :
22
- First deprecation: all major DSL moving class methods to
23
- enum, just for the sake of clarity:
24
-
25
- Ex for enum named kinds it could look like this:
26
-
27
- Class.ext_sets_to_kinds --> Class.kinds.superset_to_basic
28
- Class.ext_kinds --> Class.kinds.supersets
29
- Class.all_kinds_defs --> Class.kinds.all
30
-
31
- Class.t_kinds --> Class.kinds.t
32
- Class.t_kinds_options --> Class.kinds.t_options
33
- Class.t_named_set_kinds_options --> Class.kinds.t_named_set_options
34
-
35
- DEPRECATION
36
-
37
20
  module EnumExt
38
21
  include HumanizeHelpers # translate and humanize
39
22
  include SupersetHelpers # enum_supersets
@@ -48,7 +31,7 @@ module EnumExt
48
31
  # so calling super should be different based on ActiveRecord major version
49
32
  def enum(name = nil, values = nil, **options)
50
33
  single_enum_definition = name.present?
51
- extensions = options.delete(:ext)
34
+ extensions = [*EnumExt.config.default_helpers, *options.delete(:ext)]
52
35
  options_dup = options.dup
53
36
 
54
37
  (ActiveRecord::VERSION::MAJOR >= 7 ? super : super(options)).tap do |multiple_enum_definitions|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enum_ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 1.0.0.rc
5
5
  platform: ruby
6
6
  authors:
7
7
  - alekseyl
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-06 00:00:00.000000000 Z
11
+ date: 2023-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -181,6 +181,7 @@ files:
181
181
  - lib/enum_ext.rb
182
182
  - lib/enum_ext/annotated.rb
183
183
  - lib/enum_ext/basic_helpers.rb
184
+ - lib/enum_ext/config.rb
184
185
  - lib/enum_ext/enum_wrapper.rb
185
186
  - lib/enum_ext/humanize_helpers.rb
186
187
  - lib/enum_ext/superset_helpers.rb
@@ -200,9 +201,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
200
201
  version: '0'
201
202
  required_rubygems_version: !ruby/object:Gem::Requirement
202
203
  requirements:
203
- - - ">="
204
+ - - ">"
204
205
  - !ruby/object:Gem::Version
205
- version: '0'
206
+ version: 1.3.1
206
207
  requirements: []
207
208
  rubygems_version: 3.2.15
208
209
  signing_key: