enuminator 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +29 -4
- data/lib/enuminator/engine.rb +6 -0
- data/lib/enuminator/version.rb +5 -0
- data/lib/enuminator.rb +2 -4
- data/lib/generators/enuminator/enum/enum_generator.rb +48 -0
- data/lib/generators/enuminator/enum/templates/enumeration.rb +5 -0
- data/lib/generators/enuminator/enum/templates/enumeration.yml +6 -0
- metadata +10 -6
- data/lib/generators/enuminator/install/USAGE +0 -8
- /data/lib/{base.rb → enuminator/base.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a158e8531b8b06c8b30d57a6d9c2dbaa835912595b3928deaf84a825d29f9b29
|
4
|
+
data.tar.gz: cdc1bc4469d65be099c83d0babf6e950087b9f50944b83339d626925917788c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aae228445453ed72d03ba17be9349a501f2f5a6bf0845804c54cf0e99c62bd83b9ebb70a6aae13a27c340bae20b3d870f056cd505370d0c4c0937406a5aee104
|
7
|
+
data.tar.gz: b3356d90f3acbe66d00000bbd4f5402886bd0c042a135e95e0fef80709fa8f85090f46d4cb83cb878db509965a7269c012c2e064662a92d27c9a2f9265979083
|
data/README.md
CHANGED
@@ -26,15 +26,40 @@ And run in console
|
|
26
26
|
bundle install
|
27
27
|
```
|
28
28
|
|
29
|
-
##
|
29
|
+
## Generators
|
30
30
|
|
31
|
-
You can use a Rails generator to create `ApplicationEnumeration
|
31
|
+
You can use a Rails generator to create `ApplicationEnumeration`, because you need this main class to use enumerations:
|
32
32
|
|
33
33
|
```bash
|
34
|
-
rails g enuminator:install
|
34
|
+
bin/rails g enuminator:install
|
35
35
|
```
|
36
36
|
|
37
|
-
|
37
|
+
This command will create this file:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
# /app/enumerations/application_controller.rb
|
41
|
+
class ApplicationEnumeration < Enuminator::Base
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
You can use a Rails generator to create a specific enumeration:
|
46
|
+
|
47
|
+
```bash
|
48
|
+
bin/rails g enuminator:enum relationship_status single married divorced
|
49
|
+
```
|
50
|
+
|
51
|
+
This command will create this file:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
# /app/enumerations/application_controller.rb
|
55
|
+
class RelationshipStatus < ApplicationEnumeration
|
56
|
+
associate_values(:single, :married, :divorced)
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
60
|
+
From now you could follow the EnumerateIt references =)
|
61
|
+
|
62
|
+
## EnumerateIt References
|
38
63
|
|
39
64
|
- [Creating enumerations](https://github.com/lucascaton/enumerate_it#creating-enumerations)
|
40
65
|
- [Sorting enumerations](https://github.com/lucascaton/enumerate_it#sorting-enumerations)
|
data/lib/enuminator.rb
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Enuminator
|
4
|
+
class EnumGenerator < Rails::Generators::Base
|
5
|
+
source_root File.expand_path('templates', __dir__)
|
6
|
+
|
7
|
+
argument :attributes, type: :hash
|
8
|
+
|
9
|
+
class_option :lang, type: 'string', desc: 'Language to use in i18n', default: I18n.locale
|
10
|
+
|
11
|
+
def initialize(args, *_options)
|
12
|
+
super
|
13
|
+
|
14
|
+
@class_name = args.shift.camelize
|
15
|
+
@file_name = class_name.underscore.downcase
|
16
|
+
@values = args
|
17
|
+
@locale = options[:lang]
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'Creates the enumeration'
|
21
|
+
def create_enum
|
22
|
+
template('enumeration.rb', File.join("app/enumerations/#{file_name}.rb"))
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'Creates a locale file on config/locales'
|
26
|
+
def create_locale
|
27
|
+
template 'enumeration.yml', File.join("config/locales/#{locale}/enumerations/#{file_name}.yml")
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
attr_reader :class_name, :file_name, :locale, :values
|
33
|
+
|
34
|
+
def current_values
|
35
|
+
fields.map { |f, v| v ? "#{f}: #{v}" : ":#{f}"}.join(", ")
|
36
|
+
end
|
37
|
+
|
38
|
+
def fields
|
39
|
+
return values if attributes.empty?
|
40
|
+
|
41
|
+
if attributes.first.type == :string
|
42
|
+
attributes.map(&:name)
|
43
|
+
else
|
44
|
+
attributes.map { |attribute| [attribute.name, attribute.type] }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enuminator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Walmir Neto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: enumerate_it
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.2.4
|
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:
|
26
|
+
version: 3.2.4
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -47,9 +47,13 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- README.md
|
49
49
|
- Rakefile
|
50
|
-
- lib/base.rb
|
51
50
|
- lib/enuminator.rb
|
52
|
-
- lib/
|
51
|
+
- lib/enuminator/base.rb
|
52
|
+
- lib/enuminator/engine.rb
|
53
|
+
- lib/enuminator/version.rb
|
54
|
+
- lib/generators/enuminator/enum/enum_generator.rb
|
55
|
+
- lib/generators/enuminator/enum/templates/enumeration.rb
|
56
|
+
- lib/generators/enuminator/enum/templates/enumeration.yml
|
53
57
|
- lib/generators/enuminator/install/install_generator.rb
|
54
58
|
- lib/generators/enuminator/install/templates/application_enumeration.rb
|
55
59
|
homepage: http://github.com/owalmirneto/enuminator
|
File without changes
|