exnum 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +21 -25
- data/README.md +1 -3
- data/exnum.gemspec +6 -5
- data/lib/exnum/active_record/exnum.rb +23 -6
- data/lib/exnum/version.rb +1 -1
- metadata +38 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49cbdd6311a9cc80e75a4ef18be88d27571c93c048ca53ff7acd90673c8c4693
|
4
|
+
data.tar.gz: 1aed32ca6299bc08966e314015e480a7e7b7a6eb275492b3772aff67ece132a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84d9b0ac1bda89ff395172e025ce077f87cd0fba30164b207a61034d0b9ad01bc047899e47e8f277bdc05d8ad36f87954ca8f5f83648415fb6ab5741b1306101
|
7
|
+
data.tar.gz: 339c08e50874e5aa07dd390da07dd53a9fa6d150c43742a50323642d069dadb604c686cf972fbcdfc19c9f143dfa4d6e10d091c7a5bb95f8cdbdfd805be109ee
|
data/.circleci/config.yml
CHANGED
@@ -1,36 +1,32 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
version: 2.1
|
2
|
+
|
3
|
+
orbs:
|
4
|
+
# https://circleci.com/developer/orbs/orb/circleci/ruby?version=1.4.0
|
5
|
+
ruby: circleci/ruby@1.4.0
|
6
|
+
|
3
7
|
jobs:
|
4
8
|
build:
|
5
9
|
docker:
|
6
|
-
- image:
|
7
|
-
|
8
|
-
working_directory: ~/repo
|
9
|
-
|
10
|
+
- image: 'cimg/ruby:3.1.1'
|
10
11
|
steps:
|
11
12
|
- checkout
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# download test reporter as a static binary
|
17
|
-
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
18
|
-
chmod +x ./cc-test-reporter
|
19
|
-
|
20
|
-
- run:
|
21
|
-
name: install dependencies
|
22
|
-
command: |
|
23
|
-
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
24
|
-
|
13
|
+
- restore_cache:
|
14
|
+
name: Restore bundle cache
|
15
|
+
keys:
|
16
|
+
- bundle-3.1
|
25
17
|
- run:
|
26
|
-
name:
|
18
|
+
name: Bundle Install
|
27
19
|
command: |
|
28
|
-
|
29
|
-
bundle
|
30
|
-
|
20
|
+
bundle config set --local path 'vendor/bundle'
|
21
|
+
bundle install --jobs=4 --retry=3
|
22
|
+
- save_cache:
|
23
|
+
name: Store bundle cache
|
24
|
+
key: bundle-3.1
|
25
|
+
paths:
|
26
|
+
- vendor/bundle
|
27
|
+
- ruby/rspec-test
|
31
28
|
|
32
29
|
workflows:
|
33
|
-
|
34
|
-
workflow:
|
30
|
+
build_and_test:
|
35
31
|
jobs:
|
36
32
|
- build
|
data/README.md
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/exnum.svg)](https://badge.fury.io/rb/exnum)
|
4
4
|
[![CircleCI](https://circleci.com/gh/Kta-M/exnum.svg?style=svg)](https://circleci.com/gh/Kta-M/exnum)
|
5
|
-
[![Maintainability](https://api.codeclimate.com/v1/badges/d8d694f943658d8a5506/maintainability)](https://codeclimate.com/github/Kta-M/exnum/maintainability)
|
6
|
-
[![Test Coverage](https://api.codeclimate.com/v1/badges/d8d694f943658d8a5506/test_coverage)](https://codeclimate.com/github/Kta-M/exnum/test_coverage)
|
7
5
|
|
8
6
|
Exnum is enum extention for Rails.
|
9
7
|
This gem extends enum about i18n, associated parameters, and array for select box.
|
@@ -100,7 +98,7 @@ You can use it like this:
|
|
100
98
|
```
|
101
99
|
|
102
100
|
### enum
|
103
|
-
Of
|
101
|
+
Of course, you can use methods provided by `enum`.
|
104
102
|
```ruby
|
105
103
|
class User < ActiveRecord::Base
|
106
104
|
exnum role: [:guest, :general, :admin]
|
data/exnum.gemspec
CHANGED
@@ -19,11 +19,12 @@ 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'
|
23
|
-
spec.add_development_dependency "bundler"
|
24
|
-
spec.add_development_dependency "rake"
|
25
|
-
spec.add_development_dependency "rspec"
|
26
|
-
spec.add_development_dependency "
|
22
|
+
spec.add_dependency 'activerecord', ">= 7.0"
|
23
|
+
spec.add_development_dependency "bundler"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "rspec_junit_formatter"
|
27
|
+
spec.add_development_dependency "sqlite3"
|
27
28
|
spec.add_development_dependency "pry-rails"
|
28
29
|
spec.add_development_dependency "simplecov"
|
29
30
|
end
|
@@ -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
|
-
|
25
|
-
|
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
|
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
|
-
|
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
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exnum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kta-M
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,70 +16,84 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
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
|
-
version: '0'
|
26
|
+
version: '7.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec_junit_formatter
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: sqlite3
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
|
-
- - "
|
87
|
+
- - ">="
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
89
|
+
version: '0'
|
76
90
|
type: :development
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
|
-
- - "
|
94
|
+
- - ">="
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: pry-rails
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -134,7 +148,7 @@ homepage: https://github.com/Kta-M/exnum
|
|
134
148
|
licenses:
|
135
149
|
- MIT
|
136
150
|
metadata: {}
|
137
|
-
post_install_message:
|
151
|
+
post_install_message:
|
138
152
|
rdoc_options: []
|
139
153
|
require_paths:
|
140
154
|
- lib
|
@@ -149,8 +163,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
163
|
- !ruby/object:Gem::Version
|
150
164
|
version: '0'
|
151
165
|
requirements: []
|
152
|
-
rubygems_version: 3.
|
153
|
-
signing_key:
|
166
|
+
rubygems_version: 3.5.21
|
167
|
+
signing_key:
|
154
168
|
specification_version: 4
|
155
169
|
summary: Enum extention for Rails
|
156
170
|
test_files: []
|