ar2gostruct 0.0.5 → 0.1.0
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 +4 -4
- data/README.md +16 -6
- data/bin/ar2gostruct +5 -1
- data/lib/ar2gostruct.rb +12 -3
- data/lib/ar2gostruct/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3861f4676a60c926267fc2a6e8ae604b92122f17
|
4
|
+
data.tar.gz: af54f1c63cfac46899a8a48403d7abfb66d4b74f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a70b09199ff41a98f49d52e0897346955791fb3d6c2e0a1248023afa8001d824bcc34010871687636fd7f8e017a6cbc865d415bfc6966d47137c381610abfd4
|
7
|
+
data.tar.gz: 40a12625a3613330e8dec3a855b831ddafa397ecad0cb60415f6ab520f21b1669420d37eabffb62a35967370c937ddc67eb12f6285ae7360290915ba026cdb6f
|
data/README.md
CHANGED
@@ -29,9 +29,9 @@ ar2gostruct
|
|
29
29
|
```
|
30
30
|
this will returns
|
31
31
|
```bash
|
32
|
-
// app/models/
|
32
|
+
// app/models/user.rb
|
33
33
|
// Table name: users
|
34
|
-
type
|
34
|
+
type User struct {
|
35
35
|
Id int32 `json:"id"`
|
36
36
|
Email string `json:"email"`
|
37
37
|
EncryptedPassword string `json:"encrypted_password"`
|
@@ -43,6 +43,10 @@ type Users struct {
|
|
43
43
|
LastSignInAt time.Time `json:"last_sign_in_at"`
|
44
44
|
CurrentSignInIp string `json:"current_sign_in_ip"`
|
45
45
|
LastSignInIp string `json:"last_sign_in_ip"`
|
46
|
+
ConfirmationToken string `json:"confirmation_token"`
|
47
|
+
ConfirmedAt time.Time `json:"confirmed_at"`
|
48
|
+
ConfirmationSentAt time.Time `json:"confirmation_sent_at"`
|
49
|
+
UnconfirmedEmail string `json:"unconfirmed_email"`
|
46
50
|
CreatedAt time.Time `json:"created_at"`
|
47
51
|
UpdatedAt time.Time `json:"updated_at"`
|
48
52
|
}
|
@@ -54,10 +58,11 @@ If you're using [qbs](https://github.com/coocood/qbs#), Additional options are a
|
|
54
58
|
bundle exec rake ar2gostruct orm=qbs
|
55
59
|
# or
|
56
60
|
ar2gostruct -o qbs
|
61
|
+
# If you prefer plural struct name, "--plural" option is available.
|
57
62
|
|
58
|
-
// app/models/
|
63
|
+
// app/models/user.rb
|
59
64
|
// Table name: users
|
60
|
-
type
|
65
|
+
type User struct {
|
61
66
|
Id int32 `json:"id" qbs:"pk,notnull"`
|
62
67
|
Email string `json:"email" qbs:"notnull,default:''"`
|
63
68
|
EncryptedPassword string `json:"encrypted_password" qbs:"notnull,default:''"`
|
@@ -69,10 +74,15 @@ type Users struct {
|
|
69
74
|
LastSignInAt time.Time `json:"last_sign_in_at"`
|
70
75
|
CurrentSignInIp string `json:"current_sign_in_ip"`
|
71
76
|
LastSignInIp string `json:"last_sign_in_ip"`
|
72
|
-
|
73
|
-
|
77
|
+
ConfirmationToken string `json:"confirmation_token"`
|
78
|
+
ConfirmedAt time.Time `json:"confirmed_at"`
|
79
|
+
ConfirmationSentAt time.Time `json:"confirmation_sent_at"`
|
80
|
+
UnconfirmedEmail string `json:"unconfirmed_email"`
|
81
|
+
CreatedAt time.Time `json:"created_at" qbs:"created"`
|
82
|
+
UpdatedAt time.Time `json:"updated_at" qbs:"updated"`
|
74
83
|
}
|
75
84
|
|
85
|
+
|
76
86
|
```
|
77
87
|
|
78
88
|
Contributing
|
data/bin/ar2gostruct
CHANGED
@@ -5,7 +5,7 @@ require 'optparse'
|
|
5
5
|
require 'ar2gostruct'
|
6
6
|
|
7
7
|
OptionParser.new do |opt|
|
8
|
-
opt.banner = "Usage:
|
8
|
+
opt.banner = "Usage: ar2gostruct [options]"
|
9
9
|
|
10
10
|
opt.on('-v', '--version',
|
11
11
|
"Show the current version of this gem") do
|
@@ -16,6 +16,10 @@ OptionParser.new do |opt|
|
|
16
16
|
ENV['orm'] = orm.to_s
|
17
17
|
end
|
18
18
|
|
19
|
+
opt.on('--plural', "Pluralize struct name") do
|
20
|
+
ENV['plural'] = "true"
|
21
|
+
end
|
22
|
+
|
19
23
|
opt.on('--model-dir dir',
|
20
24
|
"Model files stored in dir rather than app/models") do |dir|
|
21
25
|
ENV['model_dir'] = dir.to_s
|
data/lib/ar2gostruct.rb
CHANGED
@@ -32,7 +32,12 @@ module Ar2gostruct
|
|
32
32
|
|
33
33
|
def self.get_schema_info(klass)
|
34
34
|
info = "// Table name: #{klass.table_name}\n"
|
35
|
-
|
35
|
+
if ENV['plural']
|
36
|
+
struct_name = klass.table_name.camelize
|
37
|
+
else
|
38
|
+
struct_name = klass.to_s.tr_s('::', '')
|
39
|
+
end
|
40
|
+
info << "type #{struct_name} struct {\n"
|
36
41
|
|
37
42
|
max_size = klass.column_names.collect{|name| name.size}.max + 1
|
38
43
|
klass.columns.each do |col|
|
@@ -56,6 +61,12 @@ module Ar2gostruct
|
|
56
61
|
if col.default
|
57
62
|
orm_option << "default:'#{col.default}'"
|
58
63
|
end
|
64
|
+
# set timestamp
|
65
|
+
if col.name == "created_at"
|
66
|
+
orm_option << "created"
|
67
|
+
elsif col.name == "updated_at"
|
68
|
+
orm_option << "updated"
|
69
|
+
end
|
59
70
|
if orm_option.present?
|
60
71
|
tags << "qbs:\"#{orm_option.join(",")}\""
|
61
72
|
end
|
@@ -95,13 +106,11 @@ module Ar2gostruct
|
|
95
106
|
end
|
96
107
|
|
97
108
|
def self.convert!
|
98
|
-
annotated = []
|
99
109
|
self.get_model_names.each do |m|
|
100
110
|
class_name = m.sub(/\.rb$/,'').camelize
|
101
111
|
begin
|
102
112
|
klass = class_name.split('::').inject(Object){ |klass,part| klass.const_get(part) }
|
103
113
|
if klass < ActiveRecord::Base && !klass.abstract_class?
|
104
|
-
annotated << class_name
|
105
114
|
self.convert_to_gostruct(klass)
|
106
115
|
end
|
107
116
|
rescue Exception => e
|
data/lib/ar2gostruct/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ar2gostruct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tatsuo Kaniwa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|