copy_tuner_client 0.0.3 → 0.0.4

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.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- copy_tuner_client (0.0.3)
4
+ copy_tuner_client (0.0.4)
5
5
  i18n (>= 0.5.0)
6
6
  json
7
7
 
@@ -123,8 +123,6 @@ GEM
123
123
  rack (~> 1.0)
124
124
  tilt (~> 1.1, != 1.3.0)
125
125
  sqlite3 (1.3.4)
126
- sqlite3-ruby (1.3.3)
127
- sqlite3 (>= 1.3.3)
128
126
  term-ansicolor (1.0.6)
129
127
  thin (1.2.11)
130
128
  daemons (>= 1.0.9)
@@ -158,7 +156,7 @@ DEPENDENCIES
158
156
  rspec (~> 2.3)
159
157
  sham_rack
160
158
  sinatra
161
- sqlite3-ruby
159
+ sqlite3
162
160
  thin
163
161
  turn
164
162
  webmock
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.add_development_dependency 'rspec', '~> 2.3'
16
16
  s.add_development_dependency 'sham_rack'
17
17
  s.add_development_dependency 'sinatra'
18
- s.add_development_dependency 'sqlite3-ruby'
18
+ s.add_development_dependency 'sqlite3'
19
19
  s.add_development_dependency 'thin'
20
20
  s.add_development_dependency 'webmock'
21
21
  s.add_development_dependency 'yard'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/mat_aki/gem/copy-tuner-ruby-client
3
3
  specs:
4
- copy_tuner_client (0.0.2)
4
+ copy_tuner_client (0.0.4)
5
5
  i18n (>= 0.5.0)
6
6
  json
7
7
 
@@ -73,8 +73,6 @@ GEM
73
73
  rack (~> 1.1)
74
74
  tilt (>= 1.2.2, < 2.0)
75
75
  sqlite3 (1.3.7)
76
- sqlite3-ruby (1.3.3)
77
- sqlite3 (>= 1.3.3)
78
76
  term-ansicolor (1.0.7)
79
77
  thin (1.5.0)
80
78
  daemons (>= 1.0.9)
@@ -103,7 +101,7 @@ DEPENDENCIES
103
101
  rspec (~> 2.3)
104
102
  sham_rack
105
103
  sinatra
106
- sqlite3-ruby
104
+ sqlite3
107
105
  thin
108
106
  turn
109
107
  webmock
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/mat_aki/gem/copy-tuner-ruby-client
3
3
  specs:
4
- copy_tuner_client (0.0.2)
4
+ copy_tuner_client (0.0.4)
5
5
  i18n (>= 0.5.0)
6
6
  json
7
7
 
@@ -113,8 +113,6 @@ GEM
113
113
  rack (~> 1.1)
114
114
  tilt (>= 1.2.2, < 2.0)
115
115
  sqlite3 (1.3.7)
116
- sqlite3-ruby (1.3.3)
117
- sqlite3 (>= 1.3.3)
118
116
  term-ansicolor (1.0.7)
119
117
  thin (1.5.0)
120
118
  daemons (>= 1.0.9)
@@ -148,7 +146,7 @@ DEPENDENCIES
148
146
  rspec (~> 2.3)
149
147
  sham_rack
150
148
  sinatra
151
- sqlite3-ruby
149
+ sqlite3
152
150
  thin
153
151
  turn
154
152
  webmock
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/mat_aki/gem/copy-tuner-ruby-client
3
3
  specs:
4
- copy_tuner_client (0.0.2)
4
+ copy_tuner_client (0.0.4)
5
5
  i18n (>= 0.5.0)
6
6
  json
7
7
 
@@ -144,8 +144,6 @@ GEM
144
144
  rack (~> 1.0)
145
145
  tilt (~> 1.1, != 1.3.0)
146
146
  sqlite3 (1.3.7)
147
- sqlite3-ruby (1.3.3)
148
- sqlite3 (>= 1.3.3)
149
147
  term-ansicolor (1.0.7)
150
148
  thin (1.5.0)
151
149
  daemons (>= 1.0.9)
@@ -185,7 +183,7 @@ DEPENDENCIES
185
183
  sass-rails
186
184
  sham_rack
187
185
  sinatra
188
- sqlite3-ruby
186
+ sqlite3
189
187
  thin
190
188
  turn
191
189
  uglifier
@@ -88,9 +88,13 @@ module CopyTunerClient
88
88
  end
89
89
 
90
90
  def flush
91
- with_queued_changes do |queued|
91
+ res = with_queued_changes do |queued|
92
92
  client.upload queued
93
93
  end
94
+
95
+ @last_uploaded_at = Time.now.utc
96
+
97
+ res
94
98
  rescue ConnectionError => error
95
99
  logger.error error.message
96
100
  end
@@ -98,10 +102,14 @@ module CopyTunerClient
98
102
  def download
99
103
  @started = true
100
104
 
101
- client.download do |downloaded_blurbs|
105
+ res = client.download do |downloaded_blurbs|
102
106
  downloaded_blurbs.reject! { |key, value| value == '' }
103
107
  lock { @blurbs = downloaded_blurbs }
104
108
  end
109
+
110
+ @last_downloaded_at = Time.now.utc
111
+
112
+ res
105
113
  rescue ConnectionError => error
106
114
  logger.error error.message
107
115
  ensure
@@ -114,6 +122,8 @@ module CopyTunerClient
114
122
  flush
115
123
  end
116
124
 
125
+ attr_reader :last_downloaded_at, :last_uploaded_at, :queued
126
+
117
127
  private
118
128
 
119
129
  attr_reader :client, :logger
@@ -1,13 +1,21 @@
1
+ require 'rack'
2
+ require 'rack/request'
3
+ require 'rack/response'
4
+
5
+ # ref) NewRelic gem https://github.com/newrelic/rpm/blob/master/lib/new_relic/rack/developer_mode.rb
6
+
1
7
  module CopyTunerClient
2
8
  # Rack middleware that synchronizes with CopyTuner during each request.
3
9
  #
4
10
  # This is injected into the Rails middleware stack in development environments.
5
11
  class RequestSync
12
+ VIEW_PATH = File.expand_path('../../../ui/views/', __FILE__)
13
+
6
14
  # @param app [Rack] the upstream app into whose responses to inject the editor
7
15
  # @param options [Hash]
8
16
  # @option options [Cache] :cache agent that should be flushed after each request
9
17
  def initialize(app, options)
10
- @app = app
18
+ @app = app
11
19
  @cache = options[:cache]
12
20
  @interval = options[:interval]
13
21
  @last_synced = options[:last_synced]
@@ -18,14 +26,91 @@ module CopyTunerClient
18
26
  # Invokes the upstream Rack application and flushes the cache after each
19
27
  # request.
20
28
  def call(env)
21
- @cache.download unless asset_request?(env) or in_interval?
22
- response = @app.call(env)
23
- @cache.flush unless asset_request?(env) or in_interval?
24
- update_last_synced unless in_interval?
25
- response
29
+ if /^\/copytuner/ =~ ::Rack::Request.new(env).path_info
30
+ dup._call(env, last_synced: @last_synced)
31
+ else
32
+ @cache.download unless asset_request?(env) or in_interval?
33
+ response = @app.call(env)
34
+ @cache.flush unless asset_request?(env) or in_interval?
35
+ update_last_synced unless in_interval?
36
+ response
37
+ end
38
+ end
39
+
40
+ protected
41
+
42
+ def _call(env, vals = {})
43
+ @req = ::Rack::Request.new(env)
44
+
45
+ case @req.path_info
46
+ when /^\/copytuner\/?$/
47
+ index
48
+ when /sync/
49
+ sync
50
+ else
51
+ @app.call(env)
52
+ end
26
53
  end
27
54
 
28
55
  private
56
+
57
+ def index
58
+ @next_sync_at = next_sync_at
59
+ render :index
60
+ end
61
+
62
+ def sync
63
+ @cache.sync
64
+ ::Rack::Response.new{|r| r.redirect('/copytuner/')}.finish
65
+ end
66
+
67
+ def render(view, layout=true)
68
+ add_rack_array = true
69
+ if view.is_a? Hash
70
+ layout = false
71
+ if view[:object]
72
+ object = view[:object]
73
+ end
74
+
75
+ if view[:collection]
76
+ return view[:collection].map do |object|
77
+ render({:partial => view[:partial], :object => object})
78
+ end.join(' ')
79
+ end
80
+
81
+ if view[:partial]
82
+ add_rack_array = false
83
+ view = "_#{view[:partial]}"
84
+ end
85
+ end
86
+ binding = Proc.new {}.binding
87
+ if layout
88
+ body = render_with_layout(view) do
89
+ render_without_layout(view, binding)
90
+ end
91
+ else
92
+ body = render_without_layout(view, binding)
93
+ end
94
+ if add_rack_array
95
+ ::Rack::Response.new(body).finish
96
+ else
97
+ body
98
+ end
99
+ end
100
+
101
+ # You have to call this with a block - the contents returned from
102
+ # that block are interpolated into the layout
103
+ def render_with_layout(view)
104
+ body = ERB.new(File.read(File.join(VIEW_PATH, 'layouts/copytuner_default.html.erb')))
105
+ body.result(Proc.new {}.binding)
106
+ end
107
+
108
+ # you have to pass a binding to this (a proc) so that ERB can have
109
+ # access to helper functions and local variables
110
+ def render_without_layout(view, binding)
111
+ ERB.new(File.read(File.join(VIEW_PATH, 'copytuner', view.to_s + '.html.erb')), nil, nil, 'frobnitz').result(binding)
112
+ end
113
+
29
114
  def asset_request?(env)
30
115
  env['PATH_INFO'] =~ /^\/assets/
31
116
  end
@@ -33,7 +118,11 @@ module CopyTunerClient
33
118
  def in_interval?
34
119
  return false if @last_synced.nil?
35
120
  return false if @interval <= 0
36
- @last_synced + @interval > Time.now.utc
121
+ next_sync_at > Time.now.utc
122
+ end
123
+
124
+ def next_sync_at
125
+ @last_synced + @interval if @last_synced and @interval
37
126
  end
38
127
 
39
128
  def update_last_synced
@@ -1,6 +1,6 @@
1
1
  module CopyTunerClient
2
2
  # Client version
3
- VERSION = '0.0.3'
3
+ VERSION = '0.0.4'
4
4
 
5
5
  # API version being used to communicate with the server
6
6
  API_VERSION = '2.0'.freeze
@@ -0,0 +1,35 @@
1
+ <div class="row">
2
+ <div class="span12">
3
+ <dl>
4
+ <dt>最終ダウンロード時間</dt>
5
+ <dd>
6
+ <%= @cache.last_downloaded_at %>
7
+ </dd>
8
+ <dt>最終アップロード時間</dt>
9
+ <dd>
10
+ <%= @cache.last_uploaded_at %>
11
+ </dd>
12
+ <dt>次回同期時間</dt>
13
+ <dd>
14
+ <%= @next_sync_at %>
15
+ </dd>
16
+ </dl>
17
+ </div>
18
+ </div>
19
+
20
+ <div class="row">
21
+ <div class="span12">
22
+ <a href="/copytuner/sync" class="btn btn-primary">
23
+ 翻訳データを同期する
24
+ </a>
25
+
26
+ <% unless @cache.queued.empty? %>
27
+ <h3>送信前翻訳キー</h3>
28
+ <ul>
29
+ <% @cache.queued.each do |key, value| %>
30
+ <li><%= key %></li>
31
+ <% end %>
32
+ </ul>
33
+ <% end %>
34
+ </div>
35
+ </div>
@@ -0,0 +1,24 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/css/bootstrap-combined.min.css" rel="stylesheet">
6
+ <style type="text/css">
7
+ body { margin-top: 60px }
8
+ </style>
9
+ <title>CopyTuner Developer Mode</title>
10
+ </head>
11
+ <body>
12
+ <div class="navbar navbar-fixed-top">
13
+ <div class="navbar-inner">
14
+ <div class="container">
15
+ <a class="brand" href="/copytuner/">CopyTuner Developer Mode</a>
16
+ </div>
17
+ </div>
18
+ </div>
19
+ <div id='main' class='container'>
20
+ <%= yield %>
21
+ </div>
22
+ <script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/js/bootstrap.min.js"></script>
23
+ </body>
24
+ </html>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: copy_tuner_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-06 00:00:00.000000000 Z
12
+ date: 2013-02-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: i18n
@@ -204,7 +204,7 @@ dependencies:
204
204
  - !ruby/object:Gem::Version
205
205
  version: '0'
206
206
  - !ruby/object:Gem::Dependency
207
- name: sqlite3-ruby
207
+ name: sqlite3
208
208
  requirement: !ruby/object:Gem::Requirement
209
209
  none: false
210
210
  requirements:
@@ -346,6 +346,8 @@ files:
346
346
  - spec/support/middleware_stack.rb
347
347
  - spec/support/writing_cache.rb
348
348
  - tmp/projects.json
349
+ - ui/views/copytuner/index.html.erb
350
+ - ui/views/layouts/copytuner_default.html.erb
349
351
  homepage: https://github.com/SonicGarden/copy-tuner-ruby-client
350
352
  licenses: []
351
353
  post_install_message:
@@ -360,7 +362,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
360
362
  version: '0'
361
363
  segments:
362
364
  - 0
363
- hash: 1018111501165444892
365
+ hash: 1986208387973179793
364
366
  required_rubygems_version: !ruby/object:Gem::Requirement
365
367
  none: false
366
368
  requirements:
@@ -369,7 +371,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
369
371
  version: '0'
370
372
  segments:
371
373
  - 0
372
- hash: 1018111501165444892
374
+ hash: 1986208387973179793
373
375
  requirements: []
374
376
  rubyforge_project:
375
377
  rubygems_version: 1.8.23