goon_model_gen 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/goon_model_gen/builder/model_builder.rb +3 -1
- data/lib/goon_model_gen/golang/enum.rb +24 -4
- data/lib/goon_model_gen/golang/package.rb +2 -3
- data/lib/goon_model_gen/source/enum.rb +17 -4
- data/lib/goon_model_gen/source/file.rb +3 -3
- data/lib/goon_model_gen/source/loader.rb +3 -1
- data/lib/goon_model_gen/templates/model/enum/01_base.go.erb +1 -1
- data/lib/goon_model_gen/templates/model/enum/02_All.go.erb +1 -1
- data/lib/goon_model_gen/templates/model/enum/02_Map.go.erb +1 -1
- data/lib/goon_model_gen/templates/model/enum/04_NameToValue.go.erb +1 -1
- data/lib/goon_model_gen/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcbd8191e356ee177b06bfbe3eac365ea41a17f2c112bffaeec6acffde03cc80
|
4
|
+
data.tar.gz: fbac547b17220f58c43edbeeb209b7b0a5db80b5dca434f56c1a1f7b14137102
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fe22afe60a09fa65c67d80bc589118a43dfdfb5140057c7643a4dac3e5de568096de8a9d8a2094443d86c84c7157fcbd806ed40bc913d79b66f7120dded5ceb
|
7
|
+
data.tar.gz: 28a70927a80f1a92ad9ae23f0dc5b17a7172091c27658fc4e7fa04ad53bb955be38fd294175bc476111ff7201ee21a357433756ce7a599d051a713992ae75114
|
@@ -29,7 +29,9 @@ module GoonModelGen
|
|
29
29
|
kind = (t.id_name && t.id_type) ? 'goon' : 'struct'
|
30
30
|
procs << Proc.new{ build_sentences('model', kind, t, go_type) }
|
31
31
|
when Source::Enum then
|
32
|
-
go_type = pkg.new_enum(t.name, t.base_type
|
32
|
+
go_type = pkg.new_enum(t.name, t.base_type).tap do |enum|
|
33
|
+
t.elements.each{|i| enum.add(i.value, i.name) }
|
34
|
+
end
|
33
35
|
procs << Proc.new{ build_sentences('model', 'enum', t, go_type) }
|
34
36
|
when Source::NamedSlice then
|
35
37
|
go_type = pkg.new_named_slice(t.name, t.base_type_name)
|
@@ -5,16 +5,36 @@ require "goon_model_gen/golang/type"
|
|
5
5
|
module GoonModelGen
|
6
6
|
module Golang
|
7
7
|
class Enum < Type
|
8
|
-
|
8
|
+
class Element
|
9
|
+
attr_reader :value, :name
|
10
|
+
def initialize(value, name)
|
11
|
+
@value, @name = value, name
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :base_type_name, :elements
|
9
16
|
attr_reader :base_type
|
10
17
|
|
11
18
|
# @param name [String]
|
12
19
|
# @param base_type_name [String]
|
13
|
-
|
14
|
-
def initialize(name, base_type_name, map)
|
20
|
+
def initialize(name, base_type_name)
|
15
21
|
super(name)
|
16
22
|
@base_type_name = base_type_name
|
17
|
-
@
|
23
|
+
@elements = []
|
24
|
+
end
|
25
|
+
|
26
|
+
# @param value [Object]
|
27
|
+
# @param name [String]
|
28
|
+
def add(value, name)
|
29
|
+
elements << Element.new(value, name)
|
30
|
+
end
|
31
|
+
|
32
|
+
# @yieldparam value [Object]
|
33
|
+
# @yieldparam name [String]
|
34
|
+
def each_value_and_name
|
35
|
+
elements.each do |i|
|
36
|
+
yield(i.value, i.name)
|
37
|
+
end
|
18
38
|
end
|
19
39
|
|
20
40
|
# @param pkgs [Packages]
|
@@ -57,10 +57,9 @@ module GoonModelGen
|
|
57
57
|
|
58
58
|
# @param name [string]
|
59
59
|
# @param base_type [String]
|
60
|
-
# @param map [Hash<Object,Hash>] elements of enum from YAML
|
61
60
|
# @return [Enum]
|
62
|
-
def new_enum(name, base_type
|
63
|
-
Enum.new(name, base_type
|
61
|
+
def new_enum(name, base_type)
|
62
|
+
Enum.new(name, base_type).tap{|s| add(s) }
|
64
63
|
end
|
65
64
|
|
66
65
|
# @param name [string]
|
@@ -5,15 +5,28 @@ require "goon_model_gen/source/type"
|
|
5
5
|
module GoonModelGen
|
6
6
|
module Source
|
7
7
|
class Enum < Type
|
8
|
-
|
8
|
+
|
9
|
+
class Element
|
10
|
+
attr_reader :value, :name
|
11
|
+
def initialize(value, name)
|
12
|
+
@value, @name = value, name
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_reader :base_type, :elements
|
9
17
|
|
10
18
|
# @param name [String]
|
11
19
|
# @param base_type [String]
|
12
|
-
# @param
|
13
|
-
def initialize(name, base_type,
|
20
|
+
# @param element_definitions [Array<Hash<Object,String>>,Hash<Object,String>]
|
21
|
+
def initialize(name, base_type, element_definitions)
|
22
|
+
unless element_definitions.all?{|i| i.is_a?(Hash) && (i.length == 1) }
|
23
|
+
raise "Enum element definitions must be an Array of 1 element Hash but was #{element_definitions.inspect}"
|
24
|
+
end
|
14
25
|
super(name)
|
15
26
|
@base_type = base_type
|
16
|
-
@
|
27
|
+
@elements = element_definitions.map do |i|
|
28
|
+
Element.new(i.keys.first, i.values.first)
|
29
|
+
end
|
17
30
|
end
|
18
31
|
end
|
19
32
|
end
|
@@ -35,10 +35,10 @@ module GoonModelGen
|
|
35
35
|
|
36
36
|
# @param name [string]
|
37
37
|
# @param base_type [String]
|
38
|
-
# @param
|
38
|
+
# @param elements [Hash<Object,Hash>] elements of enum from YAML
|
39
39
|
# @return [Enum]
|
40
|
-
def new_enum(name, base_type,
|
41
|
-
Enum.new(name, base_type,
|
40
|
+
def new_enum(name, base_type, elements)
|
41
|
+
Enum.new(name, base_type, elements).tap do |t|
|
42
42
|
t.context = self.context
|
43
43
|
types.push(t)
|
44
44
|
end
|
@@ -42,7 +42,9 @@ module GoonModelGen
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
elsif t['enum_map'].is_a?(Hash) && t['base']
|
45
|
-
f.new_enum(name, t['base'], t['enum_map'])
|
45
|
+
f.new_enum(name, t['base'], t['enum_map'].map{|k,v| {k => v}})
|
46
|
+
elsif t['enum'].is_a?(Array) && t['base']
|
47
|
+
f.new_enum(name, t['base'], t['enum'])
|
46
48
|
elsif t['slice_of'].is_a?(String)
|
47
49
|
f.new_named_slice(name, t['slice_of'])
|
48
50
|
else
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: goon_model_gen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- akm
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|