goa_model_gen 0.9.5 → 0.9.6

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: c67de54e5abf8bccd463399f089b2d1ca6dd608c771dae7e4102e3c742a63a66
4
- data.tar.gz: 9fbcbec4ed85e6e30f87ff8da15a2599c38089aa19fbefb857a1d50066f19aad
3
+ metadata.gz: fe779fe770c8cd29d871c25eba2b99849f8ac1ded301e2882626b8f77ce05423
4
+ data.tar.gz: c5ceb285bcd63b666fbc2274718f2bb6a02da528b6828cb32bf8d7057dd9257c
5
5
  SHA512:
6
- metadata.gz: b05112dfd0abc2818371f55103d60f137994e3ea60d1e8503e576c04bc0331bf2bba591b8282bd3931b9048c194d0cf5d88ba2ab4246d43d9800e5d756747512
7
- data.tar.gz: d28035567f27259a583a270dc2142083850955bc2067a71ad0954a7b987fff881fad3d6d7d94082365075018ae6139a97f85c803143d8f20e5b5bffd08f6a1f7
6
+ metadata.gz: 6c79be2c421b0190493a611a545c9c4d1c674d48ad256dd3a6715bab0132234521bd471ff6cf366f78c9fc93c5c2da80fe77a41121f7549948461cc1da2c72a1
7
+ data.tar.gz: 617355d9b10271f9e16ec9f37fd4550ae070ecf3d92d90dc334ce1d536e2ebcd8a5bbd168d5382f88645c5fe1195fc3c6086ac3c6c8508b4b28cf728e22566ba
@@ -48,7 +48,7 @@ module GoaModelGen
48
48
  def model(*paths)
49
49
  setup
50
50
  new_generator.process({
51
- 'templates/validator.go.erb' => File.join(cfg.model_dir, 'validator.go'),
51
+ 'templates/validator.go.erb' => File.join(cfg.validator_dir, 'validator.go'),
52
52
  'templates/model_base.go.erb' => File.join(cfg.model_dir, "model_base.go"),
53
53
  })
54
54
  load_types_for(paths) do |source_file|
@@ -15,6 +15,8 @@ module GoaModelGen
15
15
  base_package_path
16
16
  model_dir
17
17
  model_package_path
18
+ validator_dir
19
+ validator_package_path
18
20
  store_dir
19
21
  store_package_path
20
22
  converter_dir
@@ -32,11 +34,13 @@ module GoaModelGen
32
34
  # @swagger_yaml ||= "./swagger/swagger.yaml"
33
35
  @gofmt_disabled ||= false
34
36
  @model_dir ||= "./model"
37
+ @validator_dir ||= "./model"
35
38
  @store_dir ||= "./stores"
36
39
  @converter_dir ||= "./converters"
37
40
  @goa_gen_dir ||= "./gen"
38
41
  @base_package_path ||= default_go_package
39
42
  @model_package_path ||= join_paths(@base_package_path, @model_dir)
43
+ @validator_package_path ||= join_paths(@base_package_path, @validator_dir)
40
44
  @store_package_path ||= join_paths(@base_package_path, @store_dir)
41
45
  @converter_package_path ||= join_paths(@base_package_path, @converter_dir)
42
46
  @goa_gen_package_path ||= join_paths(@base_package_path, @goa_gen_dir)
@@ -14,6 +14,7 @@ module GoaModelGen
14
14
  attr_accessor :swagger_name
15
15
  attr_reader :type_obj
16
16
  attr_reader :datastore_tag
17
+ attr_reader :prepare_method
17
18
 
18
19
  def initialize(name, attrs)
19
20
  @name = name
@@ -26,6 +27,7 @@ module GoaModelGen
26
27
  @goa_name = attrs['goa_name']
27
28
  @swagger_name = attrs['swagger_name']
28
29
  @datastore_tag = attrs['datastore_tag']
30
+ @prepare_method = attrs['prepare_method']
29
31
  end
30
32
 
31
33
  # https://goa.design/design/overview/
@@ -1,5 +1,6 @@
1
1
  require "goa_model_gen"
2
2
 
3
+ require "erb"
3
4
  require "yaml"
4
5
 
5
6
  require "goa_model_gen/logger"
@@ -17,7 +18,11 @@ module GoaModelGen
17
18
  @path = path
18
19
  @kind = kind
19
20
  @types_key, @fields_key = types_key, fields_key
20
- @raw = YAML.load_file(path)
21
+
22
+ erb = ERB.new(File.read(path), nil, "-")
23
+ erb.filename = path
24
+ txt = erb.result
25
+ @raw = YAML.load(txt)
21
26
  end
22
27
 
23
28
  def build_type(name, d)
@@ -75,7 +75,16 @@ func <%= type.name %>ToString(v <%= type.name %>) string {
75
75
  <%- end -%>
76
76
 
77
77
  <%- source_file.types.select(&:store?).each do |model| -%>
78
+ func (m *<%= model.name %>) Assign(ref *Ref<%= model.id_golang_type.camelize %>) error {
79
+ ref.ID = m.ID
80
+ <%- if model.ref_name.present? -%>
81
+ ref.Name = m.<%= model.ref_name %>
82
+ <%- end -%>
83
+ return nil
84
+ }
85
+
78
86
  func (m *<%= model.name %>) PrepareToCreate() error {
87
+ m.PrepareFields()
79
88
  <%- if model.fields.any?{|f| f.name == "CreatedAt"} -%>
80
89
  if m.CreatedAt.IsZero() {
81
90
  m.CreatedAt = time.Now()
@@ -96,6 +105,15 @@ func (m *<%= model.name %>) PrepareToUpdate() error {
96
105
  return nil
97
106
  }
98
107
 
108
+ func (m *<%= model.name %>) PrepareFields() error {
109
+ <%- model.fields.each do |field| -%>
110
+ <%- if field.prepare_method.present? -%>
111
+ m.<%= field.name %> = m.<%= field.name %>.<%= field.prepare_method %>()
112
+ <%- end -%>
113
+ <%- end -%>
114
+ return nil
115
+ }
116
+
99
117
  func (m *<%= model.name %>) IsPersisted() bool {
100
118
  return m.ID != <%= model.id_field.zero_value_expression %>
101
119
  }
@@ -43,6 +43,7 @@ module GoaModelGen
43
43
  attr_reader :goon
44
44
  attr_reader :base
45
45
  attr_reader :conv
46
+ attr_reader :ref_name
46
47
 
47
48
  def initialize(name, attrs)
48
49
  super(name, attrs)
@@ -53,6 +54,7 @@ module GoaModelGen
53
54
  @payload_name = check_blank(attrs['payload']){ store? ? "#{@name}Payload" : @name }
54
55
  @media_type_name = check_blank(attrs['media_type']){ @name }
55
56
  @conv = attrs['conv'] || 'generate'
57
+ @ref_name = attrs['ref_name']
56
58
  end
57
59
 
58
60
  def check_blank(s)
@@ -1,3 +1,3 @@
1
1
  module GoaModelGen
2
- VERSION = "0.9.5"
2
+ VERSION = "0.9.6"
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.9.5
4
+ version: 0.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - akm
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-18 00:00:00.000000000 Z
11
+ date: 2019-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor