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 +4 -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/create/USAGE +8 -0
- data/lib/generators/enuminator/create/create_generator.rb +48 -0
- data/lib/generators/enuminator/create/templates/enumeration.rb +5 -0
- data/lib/generators/enuminator/create/templates/enumeration.yml +6 -0
- metadata +8 -2
- /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: 5b7ed6befea8e3577287b433b709c8c104d23062c15eba1e846453e12ed37e4a
|
4
|
+
data.tar.gz: 0a55ed83cdefbd768e3f7794a913259957fec5b628ba3ecc7824be23933a11f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c6a0837d70d450c18238a9a41bdd45da47fd4bdb80cf6c7c767ee659f74b3b9317b1c28e00e02c06ce80007cbca7acadb1825a1d02a5eb1690ce51d903d9115
|
7
|
+
data.tar.gz: 7a28dc4a4ffa6dbe5364fcb9ff2f7a3195b1585268d60abf33234bce476f4cf3814255d518e0acebe24e62ca6a1810a69af6965d90ec269d80e18ae3e792705d
|
data/lib/enuminator.rb
CHANGED
@@ -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
|
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.
|
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
|