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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8978af85c5d807586326e9cf0b686b9daeeb44c88d51acfd47c35ec80c8e1cec
4
- data.tar.gz: edc34f5458455299075f7d1b627c0b772772e7083279aa0f37dcb774b0a3f3d7
3
+ metadata.gz: a158e8531b8b06c8b30d57a6d9c2dbaa835912595b3928deaf84a825d29f9b29
4
+ data.tar.gz: cdc1bc4469d65be099c83d0babf6e950087b9f50944b83339d626925917788c3
5
5
  SHA512:
6
- metadata.gz: e9ed0dd77b6b8266c144ef0c88d87e726a25147b4a5d687e90b2cd3a49a396dc0e9cac43f18044eb5d82dc0345d33339370abdb512edb4104f22eefbdc59cc35
7
- data.tar.gz: '05449d389a0958471ba825cb2987f7c3164cfe2989c3ff3eee4950ca8c673a3f44b9eeaa1904be52964861f554ebba53d205b5e0358fbfed2d5195dd28ae53a7'
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
- ## Generate ApplicationEnumeration
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
- ## References
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)
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Enuminator
4
+ class Engine < Rails::Engine
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Enuminator
4
+ VERSION = "0.0.3"
5
+ end
data/lib/enuminator.rb CHANGED
@@ -2,7 +2,5 @@
2
2
 
3
3
  require "enumerate_it"
4
4
 
5
- module Enuminator
6
- class Engine < Rails::Engine
7
- end
8
- end
5
+ require 'enuminator/engine'
6
+ require 'enuminator/base'
@@ -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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class <%= class_name %> < ApplicationEnumeration
4
+ associate_values(<%= current_values %>)
5
+ end
@@ -0,0 +1,6 @@
1
+ <%= locale %>:
2
+ enumerations:
3
+ <%= file_name %>:
4
+ <%- fields.each do |value, _| -%>
5
+ <%= value %>: '<%= value.humanize -%>'
6
+ <%- 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.1
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-04 00:00:00.000000000 Z
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: 0.1.0
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: 0.1.0
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/generators/enuminator/install/USAGE
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
@@ -1,8 +0,0 @@
1
- Description:
2
- Explain the generator
3
-
4
- Example:
5
- rails g enuminator:install
6
-
7
- This will create:
8
- /app/enumerations/application_enumeration.rb
File without changes