go-on-rails 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/lib/generators/gor/go-on-rails/association.rb +10 -7
- data/lib/generators/gor/gor_generator.rb +9 -8
- data/lib/generators/gor/templates/gor_model.go.erb +2 -2
- data/lib/go/on/rails.rb +8 -0
- data/lib/go/on/rails/railtie.rb +5 -0
- data/lib/tasks/gor.rake +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a79eacecb3518a5d6a275b966c46c772af15a74
|
4
|
+
data.tar.gz: 631f955570f113bb767e83809287f5c39cc8433c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b131b9b03ecca48ba7081d7bd8e27e9228c6c7effaff59e5c0d4defb1634b5c3824d45366bf20fe7cb7ff179ef69bd8906686d19ccdb585054efbc909dbc1efc
|
7
|
+
data.tar.gz: 7a93441d049b69b48288561088ebebeca048e96ccc309c7e868a656df1fb051556722e982e4b90ee677fa02e965f7f3106a98517be78ee09d80499c571ee752b
|
data/README.md
CHANGED
@@ -21,7 +21,7 @@ Here's a simple [example(tutorial)](https://github.com/goonr/example_simple) sho
|
|
21
21
|
Add this line to your application's Gemfile:
|
22
22
|
|
23
23
|
```ruby
|
24
|
-
gem 'go-on-rails', '~> 0.1.
|
24
|
+
gem 'go-on-rails', '~> 0.1.3'
|
25
25
|
```
|
26
26
|
|
27
27
|
And then execute:
|
@@ -118,6 +118,10 @@ The `dev` branch has a whole Rails environment for development: models, seeds fo
|
|
118
118
|
- Commit, do not mess with Rakefile or version (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
119
119
|
- Send me a pull request. Bonus points for topic branches.
|
120
120
|
|
121
|
+
### Testing
|
122
|
+
|
123
|
+
Run `rails db:seed` to use the data defined in `db/seeds.rb`. And change to `go_app/models` directory to run `go test` to test generated models-related functions.
|
124
|
+
|
121
125
|
## License
|
122
126
|
|
123
127
|
See the [LICENSE](https://github.com/goonr/go-on-rails/blob/master/MIT-LICENSE) file.
|
@@ -22,8 +22,11 @@ module GoOnRails
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
type_name = "[]#{class_name}"
|
25
|
-
|
26
|
-
|
25
|
+
if col_name && type_name && (self.models.include? class_name)
|
26
|
+
info[:struct_body] << sprintf("%s %s `%s`\n", col_name, type_name, tags.join(" "))
|
27
|
+
info[:assoc_info][:has_many][col_name] = {class_name: class_name}
|
28
|
+
info[:assoc_info][:has_many][col_name].merge!(assoc.options) unless assoc.options.empty?
|
29
|
+
end
|
27
30
|
|
28
31
|
when :has_one, :belongs_to
|
29
32
|
col_name = class_name = assoc.name.to_s.camelize
|
@@ -35,13 +38,13 @@ module GoOnRails
|
|
35
38
|
end
|
36
39
|
end
|
37
40
|
type_name = class_name
|
38
|
-
|
39
|
-
|
41
|
+
if col_name && type_name && (self.models.include? class_name)
|
42
|
+
info[:struct_body] << sprintf("%s %s `%s`\n", col_name, type_name, tags.join(" "))
|
43
|
+
info[:assoc_info][assoc.macro][col_name] = {class_name: class_name}
|
44
|
+
info[:assoc_info][assoc.macro][col_name].merge!(assoc.options) unless assoc.options.empty?
|
45
|
+
end
|
40
46
|
end
|
41
47
|
info[:has_assoc_dependent] = true if assoc.options.key? :dependent
|
42
|
-
if col_name && type_name && (self.models.include? class_name)
|
43
|
-
info[:struct_body] << sprintf("%s %s `%s`\n", col_name, type_name, tags.join(" "))
|
44
|
-
end
|
45
48
|
end
|
46
49
|
info
|
47
50
|
end
|
@@ -20,20 +20,21 @@ class GorGenerator < Rails::Generators::Base
|
|
20
20
|
env_name
|
21
21
|
end
|
22
22
|
|
23
|
-
models = options[:models]
|
24
|
-
if models.empty?
|
25
|
-
models = get_all_models "app/models"
|
23
|
+
@models = options[:models]
|
24
|
+
if @models.empty?
|
25
|
+
@models = get_all_models "app/models"
|
26
26
|
else
|
27
|
-
models.map!(&:camelize)
|
27
|
+
@models.map!(&:camelize)
|
28
28
|
end
|
29
|
-
puts "
|
29
|
+
puts "Rails env: [#{rails_env}]"
|
30
|
+
puts "The models: #{@models} will be converted to a Golang App!"
|
30
31
|
|
31
|
-
models.each do |m|
|
32
|
+
@models.each do |m|
|
32
33
|
begin
|
33
34
|
klass = m.split('::').inject(Object) { |kls, part| kls.const_get(part) }
|
34
35
|
if klass < ActiveRecord::Base && !klass.abstract_class?
|
35
36
|
@model_name = klass.to_s
|
36
|
-
convertor = GoOnRails::Convertor.new(klass, models)
|
37
|
+
convertor = GoOnRails::Convertor.new(klass, @models)
|
37
38
|
@struct_info = convertor.convert
|
38
39
|
template "gor_model.go.erb", "go_app/models/gor_#{@model_name.underscore}.go"
|
39
40
|
end
|
@@ -66,7 +67,7 @@ class GorGenerator < Rails::Generators::Base
|
|
66
67
|
def get_all_models model_dir
|
67
68
|
Dir.chdir(model_dir) do
|
68
69
|
Dir["**/*.rb"]
|
69
|
-
end.map { |m| m.sub(/\.rb$/,'').camelize }
|
70
|
+
end.map { |m| m.sub(/\.rb$/,'').camelize } - ["ApplicationRecord"]
|
70
71
|
end
|
71
72
|
|
72
73
|
def create_database_config rails_env
|
@@ -220,7 +220,7 @@ func <%= @model_name %>IncludesWhere(assocs []string, sql string, args ...interf
|
|
220
220
|
for _, vv := range _<%= v[:class_name].underscore.pluralize %> {
|
221
221
|
for i, vvv := range _<%= param_name_plural %> {
|
222
222
|
<%- if v[:foreign_key] -%>
|
223
|
-
if vv.<%= v[:foreign_key].camelize %> == vvv.Id {
|
223
|
+
if vv.<%= v[:foreign_key].to_s.camelize %> == vvv.Id {
|
224
224
|
vvv.<%= k %> = append(vvv.<%= k %>, vv)
|
225
225
|
}
|
226
226
|
<%- else -%>
|
@@ -251,7 +251,7 @@ func <%= @model_name %>IncludesWhere(assocs []string, sql string, args ...interf
|
|
251
251
|
for _, vv := range _<%= v[:class_name].underscore.pluralize %> {
|
252
252
|
for i, vvv := range _<%= param_name_plural %> {
|
253
253
|
<%- if v[:foreign_key] -%>
|
254
|
-
if vv.<%= v[:foreign_key].camelize %> == vvv.Id {
|
254
|
+
if vv.<%= v[:foreign_key].to_s.camelize %> == vvv.Id {
|
255
255
|
vvv.<%= k %> = vv
|
256
256
|
}
|
257
257
|
<%- else -%>
|
data/lib/go/on/rails.rb
ADDED
data/lib/tasks/gor.rake
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: go-on-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- B1nj0y
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Modeling, developing and testing your Golang app with your familiar Rails
|
14
14
|
tools like rails generate, db migration, console etc. It is more meant to help integrating
|
@@ -31,6 +31,8 @@ files:
|
|
31
31
|
- lib/generators/gor/templates/home_controller.go.erb
|
32
32
|
- lib/generators/gor/templates/index.tmpl
|
33
33
|
- lib/generators/gor/templates/main.go
|
34
|
+
- lib/go/on/rails.rb
|
35
|
+
- lib/go/on/rails/railtie.rb
|
34
36
|
- lib/tasks/gor.rake
|
35
37
|
homepage: https://github.com/goonr/go-on-rails
|
36
38
|
licenses:
|