go-on-rails 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 890e56dfb579f5a2db328a4ee43084ce7feea0f3
4
- data.tar.gz: 6c902e303478da0632649868a56c91f8b00cbeb8
3
+ metadata.gz: 1a79eacecb3518a5d6a275b966c46c772af15a74
4
+ data.tar.gz: 631f955570f113bb767e83809287f5c39cc8433c
5
5
  SHA512:
6
- metadata.gz: f166b780f245457d28dd1ddb96af9d32d5c40f3f447da1ddfd72deecb2290b8a9f7c9304f52772cdf94be2e7b1bb849733dc353807de047127271434dc06ee1b
7
- data.tar.gz: cde88337c17f6aff8447835182796a2067c07eb8dfa4c38288bfab5e114fbf72c271c6b61318e1a78732d0072dff0676fc8281ce6978c880f10c5864a5686b87
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.2'
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
- info[:assoc_info][:has_many][col_name] = {class_name: class_name}
26
- info[:assoc_info][:has_many][col_name].merge!(assoc.options) unless assoc.options.empty?
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
- info[:assoc_info][assoc.macro][col_name] = {class_name: class_name}
39
- info[:assoc_info][assoc.macro][col_name].merge!(assoc.options) unless assoc.options.empty?
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 "The models: #{models} and Rails env [#{rails_env}] will be used to generate Golang App!"
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 -%>
@@ -0,0 +1,8 @@
1
+ module Go
2
+ module On
3
+ module Rails
4
+ end
5
+ end
6
+ end
7
+
8
+ require 'go/on/rails/railtie'
@@ -0,0 +1,5 @@
1
+ class Go::On::Rails::Railtie < Rails::Railtie
2
+ rake_tasks do
3
+ load "tasks/gor.rake"
4
+ end
5
+ end
@@ -12,6 +12,7 @@ namespace :gor do
12
12
  puts 'Installation completed!'
13
13
  end
14
14
 
15
+ desc 'Gofmt the generated codes on models'
15
16
  task :fmt do
16
17
  go_files = Rails.root.join('go_app', 'models/*.go').to_s
17
18
  system "gofmt -w #{go_files} > /dev/null 2>&1"
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.2
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-15 00:00:00.000000000 Z
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: