goa_model_gen 0.8.1 → 0.8.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: 59d53a4c0a3562be369b528c7a879e8ee10000d77b70802c4e95687905bbf720
4
- data.tar.gz: f0e8c584be29a4fb0427f26fcb8ed37aa3e22d2ec9fc3b72e39d304d5c1bca9d
3
+ metadata.gz: cca554d53fda64080cd5a64e2408b2558f548c5d6acd6f5e14848736cf2d39fa
4
+ data.tar.gz: a426126a914b0b8d3e70f8fe6e4e995540c099dcbe5eadb97705ba489a146ceb
5
5
  SHA512:
6
- metadata.gz: 0efb6a95083506ba0ee36515dd76e49a4f182879b3ef670de20d9b6b052d7d12f860373a9aaa2208b4a6573cbfa01f92ae0467d6518dcdfb89ff65f3c62d2291
7
- data.tar.gz: 9086cbbb6358edebc6e06083a1c8b1d7c496115fb5f569bec0e2e3a7bf49e84700b06fa2662db5d9053d0b889a293ac956e41aaaa374993763d7a44b947da8a1
6
+ metadata.gz: 890c57ae95750b80d5b96034c4c4844e7660c027c2e3959e53de6491bfb5f2d742922753a1ad1f7be55b28330fab3c34c650341b0053e8f9a602b56fd9608c38
7
+ data.tar.gz: 4c11251847cc608ec123875924ef01393f0d8c95e66dedf3cb03491c2cb18efe85a9c06cd79288739acbcd37b30d335a878ba8b3c6d6949547d58f56afd818b7
@@ -29,6 +29,41 @@ const (
29
29
  <%- end -%>
30
30
  )
31
31
  <%- end -%>
32
+
33
+ <%- if type.enum_map -%>
34
+ const (
35
+ <%- type.enum_map.each do |key, name| -%>
36
+ <%= type.name %><%= name.camelize %> <%= type.name %> = <%= key.inspect %>
37
+ <%- end -%>
38
+ )
39
+
40
+ var <%= type.name %>Map = map[<%= type.name %>]string{
41
+ <%- type.enum_map.each do |key, name| -%>
42
+ <%= key.inspect %>: <%= name.inspect %>,
43
+ <%- end -%>
44
+ }
45
+
46
+ func (t <%= type.name %>) String() string {
47
+ return <%= type.name %>Map[t]
48
+ }
49
+
50
+ var <%= type.name %>NameToValue = map[string]<%= type.name %>{
51
+ <%- type.enum_map.each do |key, name| -%>
52
+ <%= name.inspect %>: <%= key.inspect %>,
53
+ <%- end -%>
54
+ }
55
+
56
+ func Parse<%= type.name %>(s string) *<%= type.name %> {
57
+ val, ok := <%= type.name %>NameToValue[s]
58
+ if ok {
59
+ return &val
60
+ } else {
61
+ return nil
62
+ }
63
+ }
64
+
65
+ <%- end -%>
66
+
32
67
  <%- end -%>
33
68
 
34
69
  <%- end -%>
@@ -33,6 +33,7 @@ module GoaModelGen
33
33
 
34
34
  class Model < Type
35
35
  attr_reader :enum_items, :enum_path
36
+ attr_reader :enum_map
36
37
  attr_reader :payload, :media_type
37
38
  attr_reader :payload_name, :media_type_name
38
39
  attr_reader :goon
@@ -43,6 +44,7 @@ module GoaModelGen
43
44
  super(name, attrs)
44
45
  @base = attrs['base']
45
46
  @enum_path = attrs['enum']
47
+ @enum_map = attrs['enum_map']
46
48
  @goon = attrs['goon']
47
49
  @payload_name = check_blank(attrs['payload']){ store? ? "#{@name}Payload" : @name }
48
50
  @media_type_name = check_blank(attrs['media_type']){ @name }
@@ -1,3 +1,3 @@
1
1
  module GoaModelGen
2
- VERSION = "0.8.1"
2
+ VERSION = "0.8.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: goa_model_gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.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-01-24 00:00:00.000000000 Z
11
+ date: 2019-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor