go-on-rails 0.1.6 → 0.1.8

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: a24ab99957a404da499992b20120d30c163c5925
4
- data.tar.gz: 5009bffa97b30a0bef1209ab1b1b12bd5ec727fa
3
+ metadata.gz: 43f78729f6b807de4949b5bfff9f06dde9854808
4
+ data.tar.gz: 40b116bfcb24d9e7a3d378827adc6734ce3fa673
5
5
  SHA512:
6
- metadata.gz: 411466805ddf6f18e0797127a25cb30a9458bf5d3143b5fa3a8de2dadafd6ceeb6d385968ed96be02804ca311b73912dca0da3e1f02a329fa8548e272e47dcd6
7
- data.tar.gz: 40ddc1ef5a221c2141820ded808ec501e8064df288c92dec7c45ee75b385e91811ed2e2e04409d745144c570ccbd57e8c7a112ef6b6c7e0e849aa117908b4f6a
6
+ metadata.gz: 5ab347d8b5206dbd0ddd711dbe696ce39f56bf61b5ff8d3d37b31d48edc93931beecc10587f73754a69219008078fb804016adddf6f584e746f658185207311d
7
+ data.tar.gz: c095725253a77157d9e19b4327d55ea72f3874243a703fec2ac88b42e5e7225bcf06821dfe9ecd79fbb9983e39b404928157d4f1bc560d725d05585baf066f9f
data/README.md CHANGED
@@ -23,7 +23,7 @@ Here's a simple [example(tutorial)](https://github.com/goonr/example_simple) sho
23
23
  Add this line to your application's Gemfile:
24
24
 
25
25
  ```ruby
26
- gem 'go-on-rails', '~> 0.1.6'
26
+ gem 'go-on-rails', '~> 0.1.8'
27
27
  ```
28
28
 
29
29
  And then execute:
@@ -5,12 +5,7 @@ class GorGenerator < Rails::Generators::Base
5
5
  class_option :only_models, type: :boolean, default: false, aliases: '-o', description: "only generate models"
6
6
 
7
7
  def generate_gor
8
- env_names = %W(dev development pro production test)
9
- unless env_names.include? env_name
10
- printf("Invalid env argument: Not any of %p\n\n", env_names)
11
- exit
12
- end
13
-
8
+ env_names = ActiveRecord::Base.configurations.keys
14
9
  rails_env = case env_name
15
10
  when "dev"
16
11
  "development"
@@ -20,6 +15,11 @@ class GorGenerator < Rails::Generators::Base
20
15
  env_name
21
16
  end
22
17
 
18
+ unless env_names.include? rails_env
19
+ printf("Invalid env argument \"%s\": Not in the available list %p\n\n", rails_env, env_names)
20
+ exit
21
+ end
22
+
23
23
  @models = options[:models]
24
24
  if @models.empty?
25
25
  @models = get_all_models "app/models"
@@ -31,8 +31,9 @@ class GorGenerator < Rails::Generators::Base
31
31
 
32
32
  # read the database configuration
33
33
  @db_config = {}
34
- create_database_config(rails_env)
34
+ read_database_config(rails_env)
35
35
 
36
+ # iterate the models to generate Go codes
36
37
  @models.each do |m|
37
38
  begin
38
39
  klass = m.split('::').inject(Object) { |kls, part| kls.const_get(part) }
@@ -47,13 +48,12 @@ class GorGenerator < Rails::Generators::Base
47
48
  end
48
49
  end
49
50
 
51
+ # generate program for database connection
52
+ template "db.go.erb", "go_app/models/db.go"
53
+
50
54
  unless options[:only_models]
51
55
  # generate the main.go
52
56
  copy_file "main.go", "go_app/main.go"
53
-
54
- # generate program for database connection
55
- template "db.go.erb", "go_app/models/db.go"
56
-
57
57
  # generate the controllers and views dir
58
58
  template "home_controller.go.erb", "go_app/controllers/home_controller.go"
59
59
  copy_file "index.tmpl", "go_app/views/index.tmpl"
@@ -75,7 +75,7 @@ class GorGenerator < Rails::Generators::Base
75
75
  end.map { |m| m.sub(/\.rb$/,'').camelize } - ["ApplicationRecord"]
76
76
  end
77
77
 
78
- def create_database_config rails_env
78
+ def read_database_config rails_env
79
79
  db_conf = Rails.configuration.database_configuration[rails_env]
80
80
  db_conf["host"] = "localhost" unless db_conf["host"]
81
81
  case db_conf["adapter"]
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.6
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - B1nj0y
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-05 00:00:00.000000000 Z
11
+ date: 2017-09-18 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