schemard 0.4.0 → 0.4.1

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: ce4c14510a96e6b9ecbeb11c07c791f6dac2d397
4
- data.tar.gz: c1b1e3e296f590e8f1ad905ea5896856d3b1e210
3
+ metadata.gz: 13fe06cc263a4818c45fc93141b22df17cd1d4f9
4
+ data.tar.gz: 06e7350eca638dab57d0917ab6ed656350bb0fcb
5
5
  SHA512:
6
- metadata.gz: a771fa891f159f992c3076ec2424c83ac077633812b303a3dac12daf65edb928fc2960ffcdfe3ff26af04e348f6f128245e2e12dbf98b8a25733ccbbbf864217
7
- data.tar.gz: 9af6e49421c170b3e1c4745347b90ce26f1e86c89b12cc02a6504ed43eff1e451ef0cee4ee25c89fc952fffd4ee5ada134606757db1bc1d01a1362364316376d
6
+ metadata.gz: 812775e4e6d8c8b03d679e434089b90aa52d506f5b4d6464a4565e7cd8f9372247f9ac59d2bc55a859aef804912aad7db6d089d018708b22f7a53bacbaed9459
7
+ data.tar.gz: 040fa25567af6b21552690291a99d5f11a5a4c7add19430c720e0698d9c92724f528698974df269da0db1824b6ef647ac38af6e97a1f813c35a82686dacd9067
@@ -2,5 +2,5 @@ require_relative 'schemard/web_server'
2
2
  require_relative 'schemard/controller'
3
3
 
4
4
  module SchemaRD
5
- VERSION = "0.4.0"
5
+ VERSION = "0.4.1"
6
6
  end
@@ -15,20 +15,20 @@ module SchemaRD
15
15
  end
16
16
 
17
17
  def index(req, res)
18
- locale = localizer(req)
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: locale.lang, schema: schema)
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 = localizer(req)
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: locale.lang, schema: schema)
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 localizer(req)
60
- SchemaRD::Utils::MessageLocalizer.new(req.accept_language[0] || "en")
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
- attr_reader :lang
7
- def initialize(lang)
8
- @lang = self.dictionary && self.dictionary.has_key?(lang) ? lang : "en"
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
- @dictionary = hash
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.0
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-09-12 00:00:00.000000000 Z
11
+ date: 2017-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler