schemard 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/schemard.rb +1 -1
- data/lib/schemard/controller.rb +13 -8
- data/lib/schemard/utils/localizer.rb +9 -5
- 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: 13fe06cc263a4818c45fc93141b22df17cd1d4f9
|
4
|
+
data.tar.gz: 06e7350eca638dab57d0917ab6ed656350bb0fcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 812775e4e6d8c8b03d679e434089b90aa52d506f5b4d6464a4565e7cd8f9372247f9ac59d2bc55a859aef804912aad7db6d089d018708b22f7a53bacbaed9459
|
7
|
+
data.tar.gz: 040fa25567af6b21552690291a99d5f11a5a4c7add19430c720e0698d9c92724f528698974df269da0db1824b6ef647ac38af6e97a1f813c35a82686dacd9067
|
data/lib/schemard.rb
CHANGED
data/lib/schemard/controller.rb
CHANGED
@@ -15,20 +15,20 @@ module SchemaRD
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def index(req, res)
|
18
|
-
locale =
|
18
|
+
locale = SchemaRD::Utils::MessageLocalizer.new(default_lang(req))
|
19
19
|
schema = SchemaRD::SchemaParser.new(config.input_file).parse(with_comment: config.parse_db_comment?)
|
20
|
-
SchemaRD::Metadata.load(config: self.config, lang:
|
20
|
+
SchemaRD::Metadata.load(config: self.config, lang: default_lang(req), schema: schema)
|
21
21
|
send(req, res, render("index.html.erb", binding))
|
22
22
|
end
|
23
23
|
|
24
24
|
def show(req, res)
|
25
|
-
locale =
|
25
|
+
locale = SchemaRD::Utils::MessageLocalizer.new(default_lang(req))
|
26
26
|
match = req.path.match(/\/tables\/(\w+)/)
|
27
27
|
unless match
|
28
28
|
res.status = 404
|
29
29
|
else
|
30
30
|
schema = SchemaRD::SchemaParser.new(config.input_file).parse(with_comment: config.parse_db_comment?)
|
31
|
-
SchemaRD::Metadata.load(config: self.config, lang:
|
31
|
+
SchemaRD::Metadata.load(config: self.config, lang: default_lang(req), schema: schema)
|
32
32
|
table_name = match[1]
|
33
33
|
send(req, res, render("show.html.erb", binding))
|
34
34
|
end
|
@@ -56,8 +56,8 @@ module SchemaRD
|
|
56
56
|
|
57
57
|
private
|
58
58
|
|
59
|
-
def
|
60
|
-
|
59
|
+
def default_lang(req)
|
60
|
+
req.accept_language[0] || "en"
|
61
61
|
end
|
62
62
|
|
63
63
|
def send(req, res, body = nil)
|
@@ -89,7 +89,8 @@ module SchemaRD
|
|
89
89
|
parse_db_comment_as: "ignore",
|
90
90
|
log_output: STDOUT,
|
91
91
|
webserver_host: "127.0.0.1",
|
92
|
-
webserver_port: "10080"
|
92
|
+
webserver_port: "10080",
|
93
|
+
show_version: false
|
93
94
|
}
|
94
95
|
|
95
96
|
class Configuration < Struct.new(*DEFAULT_CONFIG.keys)
|
@@ -97,7 +98,7 @@ module SchemaRD
|
|
97
98
|
attr_reader :errors
|
98
99
|
def initialize(argv = nil)
|
99
100
|
hash = {}.merge(DEFAULT_CONFIG)
|
100
|
-
hash.merge(YAML.load_file(CONFIG_FILE)) if File.readable?(CONFIG_FILE)
|
101
|
+
hash.merge!(YAML.load_file(CONFIG_FILE)) if File.readable?(CONFIG_FILE)
|
101
102
|
|
102
103
|
unless argv.nil?
|
103
104
|
opt = OptionParser.new
|
@@ -110,6 +111,7 @@ module SchemaRD
|
|
110
111
|
opt.on('-h VAL', '--host=VAL') {|v| hash[:webserver_host] = v }
|
111
112
|
opt.on('-p VAL', '--port=VAL') {|v| hash[:webserver_port] = v }
|
112
113
|
opt.on('-l VAL', '--log-output=VAL') {|v| hash[:log_output] = self.class.str_to_io(v) }
|
114
|
+
opt.on('-v', '--version') {|v| hash[:show_version] = true }
|
113
115
|
opt.parse(argv)
|
114
116
|
end
|
115
117
|
self.assign(hash)
|
@@ -141,6 +143,9 @@ module SchemaRD
|
|
141
143
|
unless self.webserver_port =~ /^[0-9]+$/
|
142
144
|
self.errors << "WebServerPort: \"#{self.webserver_port}\" is invalid!"
|
143
145
|
end
|
146
|
+
if self.show_version
|
147
|
+
self.errors << "schemard: version-#{SchemaRD::VERSION}"
|
148
|
+
end
|
144
149
|
self.errors.empty?
|
145
150
|
end
|
146
151
|
|
@@ -3,9 +3,11 @@ require_relative 'singularizer'
|
|
3
3
|
|
4
4
|
module SchemaRD::Utils
|
5
5
|
class Localizer
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
def initialize(primary_lang)
|
7
|
+
@primary_lang = primary_lang
|
8
|
+
end
|
9
|
+
def lang
|
10
|
+
@lang ||= self.dictionary && self.dictionary.has_key?(@primary_lang) ? @primary_lang : "en"
|
9
11
|
end
|
10
12
|
def translate(key)
|
11
13
|
key.split(".").inject(self.dictionary[lang]) do |dict, k|
|
@@ -28,10 +30,12 @@ module SchemaRD::Utils
|
|
28
30
|
end
|
29
31
|
|
30
32
|
class SchemaLocalizer < Localizer
|
31
|
-
attr_reader :dictionary
|
32
33
|
def initialize(lang, hash)
|
33
34
|
super(lang)
|
34
|
-
@
|
35
|
+
@hash = hash
|
36
|
+
end
|
37
|
+
def dictionary
|
38
|
+
@hash
|
35
39
|
end
|
36
40
|
def table_name(name)
|
37
41
|
self.t("activerecord.models.#{name.singularize}")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schemard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ken TANAKA
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|