exnum 0.3.1 → 0.4.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: a0eb597ee0732dc06f4b3bc40185a72b60e66deef74d5d316375a8d30edc1c91
4
- data.tar.gz: f7feab5a390467426f4382b878e87dde7da108379474fc4088005407fe256471
3
+ metadata.gz: 49cbdd6311a9cc80e75a4ef18be88d27571c93c048ca53ff7acd90673c8c4693
4
+ data.tar.gz: 1aed32ca6299bc08966e314015e480a7e7b7a6eb275492b3772aff67ece132a8
5
5
  SHA512:
6
- metadata.gz: e7d4dd9a76bc8d775247f57dc616cc00f9b2d290d3a61a560306f72eb0f46711cc35ea6d48ec400ed835fcc9879694fd6bca708bbcb4af7aac7443000f89ce45
7
- data.tar.gz: b52fcad419966bd7ef14101e0984657e1b3949c03e6e6a6e4e15d2718d612c861d7db995226e57fd7899bec79b0a71634a1d7283a75fd98528fa850e6a793ff9
6
+ metadata.gz: 84d9b0ac1bda89ff395172e025ce077f87cd0fba30164b207a61034d0b9ad01bc047899e47e8f277bdc05d8ad36f87954ca8f5f83648415fb6ab5741b1306101
7
+ data.tar.gz: 339c08e50874e5aa07dd390da07dd53a9fa6d150c43742a50323642d069dadb604c686cf972fbcdfc19c9f143dfa4d6e10d091c7a5bb95f8cdbdfd805be109ee
data/exnum.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_dependency 'activerecord', "~> 7.0"
22
+ spec.add_dependency 'activerecord', ">= 7.0"
23
23
  spec.add_development_dependency "bundler"
24
24
  spec.add_development_dependency "rake"
25
25
  spec.add_development_dependency "rspec"
@@ -1,5 +1,6 @@
1
1
  module ActiveRecord
2
2
  module Exnum
3
+ OPTIONS = %i[_prefix _suffix]
3
4
 
4
5
  def self.prepended(base)
5
6
  base.singleton_class.class_eval { self.prepend(ClassMethods) }
@@ -21,13 +22,11 @@ module ActiveRecord
21
22
  #--------------------------------------------------------------------------
22
23
 
23
24
  def exnum(definitions)
24
- enum_definitions = definitions.each_with_object({}) do |(name, values), ret|
25
- ret[name] = extract_enums(values)
26
- end
27
- enum(**enum_definitions)
25
+ enum_num, enum_values, enum_options = extract_enum_args(definitions)
26
+ enum(enum_num, enum_values, **enum_options)
28
27
 
29
28
  pram_definitions = definitions.each_with_object({}) do |(name, values), ret|
30
- next if %i[_prefix _suffix].include?(name)
29
+ next if OPTIONS.include?(name)
31
30
 
32
31
  ret[name] = extract_params(values)
33
32
  self.send(name.to_s.pluralize).each do |k, v|
@@ -44,7 +43,25 @@ module ActiveRecord
44
43
  #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
45
44
 
46
45
  private
47
- def extract_enums(values)
46
+
47
+ def extract_enum_args(definitions)
48
+ enum_name = nil
49
+ enum_values = nil
50
+ enum_options = {}
51
+
52
+ definitions.each do |name, value|
53
+ if OPTIONS.include?(name)
54
+ enum_options[name.to_s.delete_prefix('_').to_sym] = value
55
+ else
56
+ enum_name = name
57
+ enum_values = extract_enum_values(value)
58
+ end
59
+ end
60
+
61
+ [enum_name, enum_values, enum_options]
62
+ end
63
+
64
+ def extract_enum_values(values)
48
65
  return values unless values.kind_of?(Hash)
49
66
 
50
67
  values.each_with_object({}) do |(field, value), ret|
data/lib/exnum/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Exnum
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exnum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kta-M
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-05 00:00:00.000000000 Z
11
+ date: 2024-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '7.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '7.0'
27
27
  - !ruby/object:Gem::Dependency
@@ -163,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
163
  - !ruby/object:Gem::Version
164
164
  version: '0'
165
165
  requirements: []
166
- rubygems_version: 3.3.3
166
+ rubygems_version: 3.5.21
167
167
  signing_key:
168
168
  specification_version: 4
169
169
  summary: Enum extention for Rails