goa_model_gen 0.8.4 → 0.9.0

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: 35b0d93af5777f1460e792e2b1aafb7553d0bd054558a411668687d825de5e9d
4
- data.tar.gz: 8b1ec15e0b26806474ca3005f9951529434f680e0e22b243c04d9d8467215d9f
3
+ metadata.gz: 1061248dca4fbff0b9b4517a722da29e1beb98a131381fd13b44cb36197c0b53
4
+ data.tar.gz: c94af8e7365506e8e579740351cecaf3071fbdd75db6a91b9625f69f08cb43b0
5
5
  SHA512:
6
- metadata.gz: b68b7d2d1488af468dc14a78ab150d22becfcacd852aa8ec87fbf6b40b107bcaa40688154205ff3a727a6d87a7536cb3f39ca492b612188782c7ac6debd780d6
7
- data.tar.gz: bb0dcd08ac16663d0cb3f54dfee59ed5e52d3a0a4e75872fdf2f9665e573a774d2d70ffb2de6fabd117ac337bc1eb40e73735764ca3701aa5edce74c6540bff2
6
+ metadata.gz: 8094e4fe0dc6d4e76b7c7f063108ef04748b014e8688a95b59f334aa79aea2feb14b91cc46c939fe1b7ba68ee50b0ce0a6f61176ad5024176e15183ff6d93634
7
+ data.tar.gz: '0117000180a31a443396f37768774dd8c6db73bf7abae228f2468ff59d7cc02d1d662a1cfeb3ca61e30bb1bb7ef4fe2e61e3d4334947d63df082285db683be1d'
@@ -60,10 +60,18 @@ module GoaModelGen
60
60
  "templates/goon.go.erb" => File.join(cfg.store_dir, "goon_store", "goon.go"),
61
61
  })
62
62
  load_types_for(paths) do |source_file|
63
- new_generator.tap{|g| g.source_file = source_file }.process({
64
- 'templates/store.go.erb' => File.join(cfg.store_dir, source_file.basename, "store.go"),
65
- 'templates/store_validation.go.erb' => File.join(cfg.store_dir, source_file.basename, "validation.go"),
66
- })
63
+ source_file.types.select(&:store?).each do |model|
64
+ basename = model.name.underscore
65
+ variables = {
66
+ model: model,
67
+ model_basename: basename,
68
+ }
69
+
70
+ new_generator.tap{|g| g.source_file = source_file }.process({
71
+ 'templates/store.go.erb' => File.join(cfg.store_dir, basename, "store.go"),
72
+ 'templates/store_validation.go.erb' => File.join(cfg.store_dir, basename, "validation.go"),
73
+ }, variables)
74
+ end
67
75
  end
68
76
  end
69
77
 
@@ -114,8 +114,8 @@ module GoaModelGen
114
114
  thor.create_file(output_path, content, options)
115
115
  end
116
116
 
117
- def process(temp_path_to_dest_path)
118
- temp_path_to_dest_path.each{|src, dest| run(src, dest) }
117
+ def process(temp_path_to_dest_path, variables = {}, &block)
118
+ temp_path_to_dest_path.each{|src, dest| run(src, dest, variables, &block) }
119
119
  end
120
120
  end
121
121
  end
@@ -1,6 +1,5 @@
1
- <%- package source_file.basename -%>
1
+ <%- package model_basename -%>
2
2
 
3
- <%- source_file.types.select(&:store?).each do |model| -%>
4
3
  <%- store_name = "#{model.name}Store" -%>
5
4
  <%-
6
5
  import "context"
@@ -12,7 +11,14 @@
12
11
 
13
12
  model_name = "model.#{model.name}"
14
13
  -%>
14
+ type <%= store_name %>Binder interface {
15
+ Query(q *datastore.Query) *datastore.Query
16
+ Visible(m *model.<%= model.name %>) bool
17
+ Prepare(m *model.<%= model.name %>)
18
+ }
19
+
15
20
  type <%= store_name %> struct{
21
+ Binder <%= store_name %>Binder
16
22
  <%- if model.parent -%>
17
23
  ParentKey *datastore.Key
18
24
  <%- end -%>
@@ -48,7 +54,11 @@ func (s *<%= store_name %>) Query(ctx context.Context) *datastore.Query {
48
54
  g := goon.FromContext(ctx)
49
55
  k := g.Kind(new(<%= model_name %>))
50
56
  // log.Infof(ctx, "Kind for <%= model_name %> is %v\n", k)
51
- return datastore.NewQuery(k)
57
+ q := datastore.NewQuery(k)
58
+ if s.Binder != nil {
59
+ q = s.Binder.Query(q)
60
+ }
61
+ return q
52
62
  }
53
63
 
54
64
  func (s *<%= store_name %>) ByID(ctx context.Context, <%= model.id_name_var %> <%= model.id_golang_type %>) (*<%= model_name %>, error) {
@@ -70,16 +80,7 @@ func (s *<%= store_name %>) ByKey(ctx context.Context, key *datastore.Key) (*<%=
70
80
  return nil, err
71
81
  }
72
82
 
73
- <%- if model.parent -%>
74
- r := <%= model_name %>{ParentKey: key.Parent(), <%= model.id_name %>: key.<%= model.key_id_method %>()}
75
- <%- else -%>
76
- r := <%= model_name %>{<%= model.id_name %>: key.<%= model.key_id_method %>()}
77
- <%- end -%>
78
- err := s.Get(ctx, &r)
79
- if err != nil {
80
- return nil, err
81
- }
82
- return &r, nil
83
+ return s.ByID(ctx, key.IntID())
83
84
  }
84
85
 
85
86
  func (s *<%= store_name %>) Get(ctx context.Context, m *<%= model_name %>) error {
@@ -96,7 +97,11 @@ func (s *<%= store_name %>) Get(ctx context.Context, m *<%= model_name %>) error
96
97
  }
97
98
  <%- end -%>
98
99
 
99
- return nil
100
+ if s.Binder != nil && !s.Binder.Visible(m) {
101
+ return datastore.ErrNoSuchEntity
102
+ }
103
+
104
+ return nil
100
105
  }
101
106
 
102
107
  func (s *<%= store_name %>) IsValidKey(ctx context.Context, key *datastore.Key) error {
@@ -172,6 +177,9 @@ func (s *<%= store_name %>) Update(ctx context.Context, m *<%= model_name %>) (*
172
177
  }
173
178
 
174
179
  func (s *<%= store_name %>) PutWith(ctx context.Context, m *<%= model_name %>, f func() error) (*datastore.Key, error) {
180
+ if s.Binder != nil {
181
+ s.Binder.Prepare(m)
182
+ }
175
183
  if err := s.Validate(ctx, m); err != nil {
176
184
  return nil, err
177
185
  }
@@ -260,5 +268,3 @@ func (s *<%= store_name %>) ValidateUniqueness(ctx context.Context, m *<%= model
260
268
  }
261
269
  return nil
262
270
  }
263
-
264
- <%- end -%>
@@ -6,6 +6,7 @@ import (
6
6
  "os"
7
7
  "reflect"
8
8
  "regexp"
9
+ "sort"
9
10
  )
10
11
 
11
12
  func process(objectMap map[string][]interface{}, ptn *regexp.Regexp) {
@@ -27,6 +28,10 @@ func process(objectMap map[string][]interface{}, ptn *regexp.Regexp) {
27
28
  }
28
29
  }
29
30
 
31
+ sort.Slice(dataTypes, func(i, j int) bool {
32
+ return (dataTypes[i].PkgPath +"."+ dataTypes[i].Name) < (dataTypes[j].PkgPath +"."+ dataTypes[j].Name)
33
+ })
34
+
30
35
  res[key] = dataTypes
31
36
  }
32
37
 
@@ -1,3 +1,3 @@
1
1
  module GoaModelGen
2
- VERSION = "0.8.4"
2
+ VERSION = "0.9.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: goa_model_gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - akm