enuminator 0.0.1 → 0.0.2

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: 5b7ed6befea8e3577287b433b709c8c104d23062c15eba1e846453e12ed37e4a
4
+ data.tar.gz: 0a55ed83cdefbd768e3f7794a913259957fec5b628ba3ecc7824be23933a11f7
5
5
  SHA512:
6
- metadata.gz: e9ed0dd77b6b8266c144ef0c88d87e726a25147b4a5d687e90b2cd3a49a396dc0e9cac43f18044eb5d82dc0345d33339370abdb512edb4104f22eefbdc59cc35
7
- data.tar.gz: '05449d389a0958471ba825cb2987f7c3164cfe2989c3ff3eee4950ca8c673a3f44b9eeaa1904be52964861f554ebba53d205b5e0358fbfed2d5195dd28ae53a7'
6
+ metadata.gz: 7c6a0837d70d450c18238a9a41bdd45da47fd4bdb80cf6c7c767ee659f74b3b9317b1c28e00e02c06ce80007cbca7acadb1825a1d02a5eb1690ce51d903d9115
7
+ data.tar.gz: 7a28dc4a4ffa6dbe5364fcb9ff2f7a3195b1585268d60abf33234bce476f4cf3814255d518e0acebe24e62ca6a1810a69af6965d90ec269d80e18ae3e792705d
@@ -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.2"
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,8 @@
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
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Enuminator
4
+ class CreateGenerator < 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 %>Enumeration < 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,7 +1,7 @@
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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Walmir Neto
@@ -47,8 +47,14 @@ extra_rdoc_files: []
47
47
  files:
48
48
  - README.md
49
49
  - Rakefile
50
- - lib/base.rb
51
50
  - lib/enuminator.rb
51
+ - lib/enuminator/base.rb
52
+ - lib/enuminator/engine.rb
53
+ - lib/enuminator/version.rb
54
+ - lib/generators/enuminator/create/USAGE
55
+ - lib/generators/enuminator/create/create_generator.rb
56
+ - lib/generators/enuminator/create/templates/enumeration.rb
57
+ - lib/generators/enuminator/create/templates/enumeration.yml
52
58
  - lib/generators/enuminator/install/USAGE
53
59
  - lib/generators/enuminator/install/install_generator.rb
54
60
  - lib/generators/enuminator/install/templates/application_enumeration.rb
File without changes