chronuscop_client 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +22 -0
- data/Gemfile.lock +28 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +56 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/chronuscop_client.gemspec +74 -0
- data/lib/chronuscop_client.rb +20 -0
- data/lib/chronuscop_client/chronus_backend.rb +26 -0
- data/lib/chronuscop_client/configuration.rb +53 -0
- data/lib/chronuscop_client/railtie.rb +37 -0
- data/lib/chronuscop_client/synchronizer.rb +126 -0
- data/lib/tasks/chronuscop_client_tasks.rake +59 -0
- data/test/helper.rb +18 -0
- data/test/test_chronuscop_client.rb +7 -0
- metadata +173 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
# These are runtime-dependencies (i.e these gems are necessary to use the chronucop_client gem / plugin )
|
4
|
+
# The following versions have been tested.
|
5
|
+
# gem 'mechanize','1.0.0'
|
6
|
+
# gem 'xml-simple', '1.0.15'
|
7
|
+
# gem 'redis', '2.2.1'
|
8
|
+
|
9
|
+
gem 'mechanize','~>1.0.0'
|
10
|
+
gem 'xml-simple','~>1.0.15'
|
11
|
+
gem 'redis','~>2.2.1'
|
12
|
+
gem 'SystemTimer','~>1.2.3'
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
# Add dependencies to develop your gem here.
|
17
|
+
# Include everything needed to run rake, tests, features, etc.
|
18
|
+
group :development do
|
19
|
+
gem "bundler", "~> 1.0.0"
|
20
|
+
gem "jeweler", "~> 1.6.2"
|
21
|
+
gem "rcov", ">=0"
|
22
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
SystemTimer (1.2.3)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.6.2)
|
7
|
+
bundler (~> 1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
mechanize (1.0.0)
|
11
|
+
nokogiri (>= 1.2.1)
|
12
|
+
nokogiri (1.4.4)
|
13
|
+
rake (0.9.2)
|
14
|
+
rcov (0.9.9)
|
15
|
+
redis (2.2.1)
|
16
|
+
xml-simple (1.0.15)
|
17
|
+
|
18
|
+
PLATFORMS
|
19
|
+
ruby
|
20
|
+
|
21
|
+
DEPENDENCIES
|
22
|
+
SystemTimer (~> 1.2.3)
|
23
|
+
bundler (~> 1.0.0)
|
24
|
+
jeweler (~> 1.6.2)
|
25
|
+
mechanize (~> 1.0.0)
|
26
|
+
rcov
|
27
|
+
redis (~> 2.2.1)
|
28
|
+
xml-simple (~> 1.0.15)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 ajey
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
= chronuscop_client
|
2
|
+
|
3
|
+
Please refer to the setup instructions here.
|
4
|
+
http://chronuscop.heroku.com/pages/help
|
5
|
+
|
6
|
+
Note:
|
7
|
+
* You will have to run the rake task to upload the keys to the chronuscop-server after changing to
|
8
|
+
your app's root directory..
|
9
|
+
|
10
|
+
Sample chronuscop.yml config looks like this.
|
11
|
+
development:
|
12
|
+
redis_db_number: 0
|
13
|
+
redis_server_port: 0
|
14
|
+
project_number: 1
|
15
|
+
api_token: OWPrhg3M8fjsB16K1bke
|
16
|
+
chronuscop_server_address: http://localhost:3000
|
17
|
+
sync_time_interval: 10
|
18
|
+
|
19
|
+
test:
|
20
|
+
redis_db_number: 0
|
21
|
+
redis_server_port: 0
|
22
|
+
project_number: 1
|
23
|
+
api_token: OWPrhg3M8fjsB16K1bke
|
24
|
+
chronuscop_server_address: http://localhost:3000
|
25
|
+
sync_time_interval: 10
|
26
|
+
|
27
|
+
production:
|
28
|
+
redis_db_number: 0
|
29
|
+
redis_server_port: 0
|
30
|
+
project_number: 1
|
31
|
+
api_token: QVVBg5tYjbUHtb5LVQxg
|
32
|
+
chronuscop_server_address: http://localhost:3000
|
33
|
+
sync_time_interval: 300
|
34
|
+
|
35
|
+
|
36
|
+
* The chronuscop_client uses a temporary file located in RAILS_ROOT/tmp/chronuscop.tmp for
|
37
|
+
writing the last synchronization time. Make sure that the tmp directory is present in
|
38
|
+
the rails root directory. If it is not present, create one.
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
== Contributing to chronuscop_client
|
43
|
+
|
44
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
45
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
46
|
+
* Fork the project
|
47
|
+
* Start a feature/bugfix branch
|
48
|
+
* Commit and push until you are happy with your contribution
|
49
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
50
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
51
|
+
|
52
|
+
== Copyright
|
53
|
+
|
54
|
+
Copyright (c) 2011 ajey. See LICENSE.txt for
|
55
|
+
further details.
|
56
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "chronuscop_client"
|
18
|
+
gem.homepage = "http://github.com/ajey/chronuscop_client"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = "chronuscop_client gem to easily integrate your rails app with the chronuscop server."
|
21
|
+
gem.description = "This gem helps you to easily tweak your rails app to use the chronuscop server."
|
22
|
+
gem.email = "ajey@chronus.com"
|
23
|
+
gem.authors = ["ajey"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'rcov/rcovtask'
|
36
|
+
Rcov::RcovTask.new do |test|
|
37
|
+
test.libs << 'test'
|
38
|
+
test.pattern = 'test/**/test_*.rb'
|
39
|
+
test.verbose = true
|
40
|
+
test.rcov_opts << '--exclude "gems/*"'
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "chronuscop_client #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{chronuscop_client}
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["ajey"]
|
12
|
+
s.date = %q{2011-07-11}
|
13
|
+
s.description = %q{This gem helps you to easily tweak your rails app to use the chronuscop server.}
|
14
|
+
s.email = %q{ajey@chronus.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"chronuscop_client.gemspec",
|
28
|
+
"lib/chronuscop_client.rb",
|
29
|
+
"lib/chronuscop_client/chronus_backend.rb",
|
30
|
+
"lib/chronuscop_client/configuration.rb",
|
31
|
+
"lib/chronuscop_client/railtie.rb",
|
32
|
+
"lib/chronuscop_client/synchronizer.rb",
|
33
|
+
"lib/tasks/chronuscop_client_tasks.rake",
|
34
|
+
"test/helper.rb",
|
35
|
+
"test/test_chronuscop_client.rb"
|
36
|
+
]
|
37
|
+
s.homepage = %q{http://github.com/ajey/chronuscop_client}
|
38
|
+
s.licenses = ["MIT"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = %q{1.3.6}
|
41
|
+
s.summary = %q{chronuscop_client gem to easily integrate your rails app with the chronuscop server.}
|
42
|
+
|
43
|
+
if s.respond_to? :specification_version then
|
44
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_runtime_dependency(%q<mechanize>, ["~> 1.0.0"])
|
49
|
+
s.add_runtime_dependency(%q<xml-simple>, ["~> 1.0.15"])
|
50
|
+
s.add_runtime_dependency(%q<redis>, ["~> 2.2.1"])
|
51
|
+
s.add_runtime_dependency(%q<SystemTimer>, ["~> 1.2.3"])
|
52
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
53
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
|
54
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<mechanize>, ["~> 1.0.0"])
|
57
|
+
s.add_dependency(%q<xml-simple>, ["~> 1.0.15"])
|
58
|
+
s.add_dependency(%q<redis>, ["~> 2.2.1"])
|
59
|
+
s.add_dependency(%q<SystemTimer>, ["~> 1.2.3"])
|
60
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
61
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
62
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
63
|
+
end
|
64
|
+
else
|
65
|
+
s.add_dependency(%q<mechanize>, ["~> 1.0.0"])
|
66
|
+
s.add_dependency(%q<xml-simple>, ["~> 1.0.15"])
|
67
|
+
s.add_dependency(%q<redis>, ["~> 2.2.1"])
|
68
|
+
s.add_dependency(%q<SystemTimer>, ["~> 1.2.3"])
|
69
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
70
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
71
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'chronuscop_client/configuration'
|
2
|
+
|
3
|
+
module ChronuscopClient
|
4
|
+
|
5
|
+
# defining necessary objects which will be used.
|
6
|
+
class << self
|
7
|
+
|
8
|
+
# The configuration object stores all the configuration information.
|
9
|
+
attr_accessor :configuration_object
|
10
|
+
|
11
|
+
# The synchronizer object.
|
12
|
+
attr_accessor :synchronizer_object
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.test
|
17
|
+
puts "Works"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'redis'
|
3
|
+
|
4
|
+
module ChronuscopClient
|
5
|
+
|
6
|
+
# This backend will be used for translations.
|
7
|
+
class ChronusBackend
|
8
|
+
|
9
|
+
def initialize(redis_db_number = 0)
|
10
|
+
@redis_agent = Redis.new(:db => redis_db_number)
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
def [](key)
|
15
|
+
@redis_agent[key]
|
16
|
+
end
|
17
|
+
|
18
|
+
def []=(key,value)
|
19
|
+
@redis_agent[key] = value
|
20
|
+
end
|
21
|
+
|
22
|
+
def keys
|
23
|
+
@redis_agent.keys
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# requiring gem dependencies.
|
2
|
+
require 'rubygems'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
# requiring other files.
|
6
|
+
require 'chronuscop_client/synchronizer'
|
7
|
+
require 'chronuscop_client/railtie' if defined?(Rails)
|
8
|
+
|
9
|
+
# The configuration class which stores all the configurable options for the chronuscop client.
|
10
|
+
module ChronuscopClient
|
11
|
+
|
12
|
+
class Configuration
|
13
|
+
# The redis database number.(Redis doesn't support database names)
|
14
|
+
attr_accessor :redis_db_number
|
15
|
+
|
16
|
+
# The redis server port number.
|
17
|
+
attr_accessor :redis_server_port
|
18
|
+
|
19
|
+
# The yaml file location in the rails app.
|
20
|
+
attr_accessor :yaml_file_location
|
21
|
+
|
22
|
+
# The api token.
|
23
|
+
attr_accessor :api_token
|
24
|
+
|
25
|
+
# The project number.(in the chronuscop server.)
|
26
|
+
attr_accessor :project_number
|
27
|
+
|
28
|
+
# The chronuscop server address.
|
29
|
+
attr_accessor :chronuscop_server_address
|
30
|
+
|
31
|
+
# The rails environment.
|
32
|
+
attr_accessor :rails_environment
|
33
|
+
|
34
|
+
# The rails root directory.
|
35
|
+
attr_accessor :rails_root_dir
|
36
|
+
|
37
|
+
# The time between successive synchronizations.
|
38
|
+
attr_accessor :sync_time_interval
|
39
|
+
|
40
|
+
# rails root directory must be set before calling this.
|
41
|
+
def load_yaml_configuration
|
42
|
+
yaml_config = YAML.load_file("#{@rails_root_dir}/config/chronuscop.yml")
|
43
|
+
@redis_db_number = yaml_config[@rails_environment]['redis_db_number']
|
44
|
+
@redis_server_port = yaml_config[@rails_environment]['redis_server_port']
|
45
|
+
@project_number = yaml_config[@rails_environment]['project_number']
|
46
|
+
@api_token = yaml_config[@rails_environment]['api_token']
|
47
|
+
@chronuscop_server_address = yaml_config[@rails_environment]['chronuscop_server_address']
|
48
|
+
@sync_time_interval = yaml_config[@rails_environment]['sync_time_interval']
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'chronuscop_client'
|
2
|
+
require 'rails'
|
3
|
+
|
4
|
+
module ChronuscopClient
|
5
|
+
# Connects to integration points for Rails 3 applications
|
6
|
+
class Railtie < ::Rails::Railtie
|
7
|
+
initializer :initialize_chronuscop_rails, :after => :before_initialize do |app|
|
8
|
+
|
9
|
+
# to be removed.
|
10
|
+
puts "Initializing the chronuscop clients."
|
11
|
+
|
12
|
+
# creating a new configuration object.
|
13
|
+
ChronuscopClient.configuration_object = ChronuscopClient::Configuration.new
|
14
|
+
|
15
|
+
# setting the root directory.
|
16
|
+
ChronuscopClient.configuration_object.rails_root_dir = ::Rails.root
|
17
|
+
|
18
|
+
# setting the rails environment.
|
19
|
+
ChronuscopClient.configuration_object.rails_environment = ::Rails.env
|
20
|
+
|
21
|
+
# reading the YAML file (app/config/chronuscop.yml)
|
22
|
+
ChronuscopClient.configuration_object.load_yaml_configuration
|
23
|
+
|
24
|
+
# Setting the I18n backend for the rails application.
|
25
|
+
I18n.backend = I18n::Backend::KeyValue.new(Redis.new(:db => ChronuscopClient.configuration_object.redis_db_number))
|
26
|
+
|
27
|
+
# creating a new synchronizer object.
|
28
|
+
ChronuscopClient.synchronizer_object = ChronuscopClient::Synchronizer.new(ChronuscopClient.configuration_object.redis_db_number)
|
29
|
+
ChronuscopClient.synchronizer_object.start
|
30
|
+
end
|
31
|
+
|
32
|
+
rake_tasks do
|
33
|
+
load "tasks/chronuscop_client_tasks.rake"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'mechanize' # this is the http-client used.
|
3
|
+
require 'xmlsimple' # necessary to parse xml response from the server.
|
4
|
+
require 'redis' # Redis client to interact with the redis key-value store.
|
5
|
+
|
6
|
+
module ChronuscopClient
|
7
|
+
|
8
|
+
# This class handles synchronizing local and remote keys.
|
9
|
+
class Synchronizer
|
10
|
+
attr_accessor :run_synchronizer
|
11
|
+
|
12
|
+
def initialize(redis_db_number = 0)
|
13
|
+
@mechanize_agent = Mechanize.new # mechanize client.
|
14
|
+
@redis_agent = Redis.new(:db => redis_db_number) # redis client.
|
15
|
+
@run_synchronizer = true
|
16
|
+
end
|
17
|
+
|
18
|
+
# Function to write the last update time to a temporary file.
|
19
|
+
def write_last_update(last_update_at)
|
20
|
+
# Check for the presence of the tmp directory.
|
21
|
+
if(! File::directory?("tmp")) then
|
22
|
+
Dir.mkdir("tmp")
|
23
|
+
end
|
24
|
+
|
25
|
+
f = File.new("tmp/chronuscop.tmp","w")
|
26
|
+
f.printf("%d",last_update_at.to_i)
|
27
|
+
f.close()
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def get_last_update_at
|
32
|
+
# Check for the presence of the file.
|
33
|
+
if(! File::exists?("tmp/chronuscop.tmp")) then
|
34
|
+
return 0
|
35
|
+
else
|
36
|
+
last_update_at = File.read("tmp/chronuscop.tmp").to_i
|
37
|
+
return last_update_at
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def start
|
42
|
+
Thread.new { keep_in_sync }
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def keep_in_sync
|
47
|
+
while(@run_synchronizer)
|
48
|
+
|
49
|
+
# Sleep for 'x' seconds. 'x' is specified in the config file.
|
50
|
+
sleep(ChronuscopClient.configuration_object.sync_time_interval)
|
51
|
+
|
52
|
+
# Calling the sync_it_now function.
|
53
|
+
sync_it_now
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# To convert xml_time received from the server to integer.
|
58
|
+
def xml_time_to_integer(str)
|
59
|
+
arr = str.gsub(/T|Z|:/,"-").split(/-/)
|
60
|
+
year = arr[0]
|
61
|
+
month = arr[1]
|
62
|
+
day = arr[2]
|
63
|
+
hour = arr[3]
|
64
|
+
min = arr[4]
|
65
|
+
sec = arr[5]
|
66
|
+
Time.utc(year,month,day,hour,min,sec).to_i
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
# This method keeps the remote-keys and the local-keys synchronized.
|
72
|
+
# This method should be called only after initializing the configuration
|
73
|
+
# object as it uses those configuration values.
|
74
|
+
def sync_it_now
|
75
|
+
puts "Attempt Sync"
|
76
|
+
|
77
|
+
# Getting the last sync value.
|
78
|
+
last_update_at = get_last_update_at
|
79
|
+
|
80
|
+
# querying the page.
|
81
|
+
page = @mechanize_agent.get("#{ChronuscopClient.configuration_object.chronuscop_server_address}/projects/#{ChronuscopClient.configuration_object.project_number}/translations.xml/?auth_token=#{ChronuscopClient.configuration_object.api_token}&last_update_at=#{last_update_at}")
|
82
|
+
|
83
|
+
# converting the returned xml page into a hash.
|
84
|
+
words_hash = XmlSimple.xml_in(page.body)
|
85
|
+
|
86
|
+
# catching the case when no-translations are returned.
|
87
|
+
if(!words_hash) then
|
88
|
+
puts "Nothing new added."
|
89
|
+
return
|
90
|
+
end
|
91
|
+
|
92
|
+
# collecting the translations array.
|
93
|
+
all_translations = words_hash["translation"]
|
94
|
+
|
95
|
+
# catching the case when no-translations are returned.
|
96
|
+
if(!all_translations) then
|
97
|
+
puts "Nothing new added."
|
98
|
+
return
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
all_translations.each do |t|
|
103
|
+
# Inserting into the redis store.
|
104
|
+
@redis_agent.set "#{t["key"]}","#{t["value"]}"
|
105
|
+
|
106
|
+
# Bad hack used here. Should fix this.
|
107
|
+
str = t["updated-at"][0]["content"]
|
108
|
+
key_updated_at = xml_time_to_integer(str)
|
109
|
+
|
110
|
+
# Updating the value last_update_at
|
111
|
+
if(key_updated_at > last_update_at) then
|
112
|
+
last_update_at = key_updated_at
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
# Writing the value of last_update_at to the file.
|
118
|
+
write_last_update(last_update_at.to_i)
|
119
|
+
puts "Finished synchronizing !!!"
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
|
@@ -0,0 +1,59 @@
|
|
1
|
+
namespace :chronuscop do
|
2
|
+
desc "Rake task to upload english keys and translations from the yaml file."
|
3
|
+
task :deploy => :environment do
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
require 'yaml'
|
8
|
+
require 'xmlsimple'
|
9
|
+
require 'mechanize'
|
10
|
+
require 'redis'
|
11
|
+
|
12
|
+
|
13
|
+
# function to flatten a hash separating each level with '.' character.
|
14
|
+
def make_hash_one_dimensional(input = {}, output = {}, options = {})
|
15
|
+
input.each do |key, value|
|
16
|
+
key = options[:prefix].nil? ? "#{key}" :
|
17
|
+
"#{options[:prefix]}#{options[:delimiter]||"_"}#{key}"
|
18
|
+
if value.is_a? Hash
|
19
|
+
make_hash_one_dimensional(value, output, :prefix => key,:delimiter => ".")
|
20
|
+
else
|
21
|
+
output[key] = value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
output
|
25
|
+
end
|
26
|
+
|
27
|
+
# Reading the configuration yaml file.
|
28
|
+
chronuscop_config = YAML.load_file('./config/chronuscop.yml')
|
29
|
+
|
30
|
+
if( ! RAILS_ENV) # if no option is passed from the command line
|
31
|
+
RAILS_ENV = "development"
|
32
|
+
end
|
33
|
+
|
34
|
+
# reading the yaml files.
|
35
|
+
h = YAML.load_file('./config/locales/default.yml')
|
36
|
+
|
37
|
+
# converting the yaml file into a one dimensional hash.
|
38
|
+
one_dim_hash = make_hash_one_dimensional(h)
|
39
|
+
|
40
|
+
# Adding the initial set of key-value pairs into
|
41
|
+
# the redis database as english key-value pairs.
|
42
|
+
|
43
|
+
# Creating the redis client object.
|
44
|
+
redis_agent = Redis.new(:db => chronuscop_config[RAILS_ENV]["redis_db_number"])
|
45
|
+
one_dim_hash.each do |key,value|
|
46
|
+
new_key = key.sub(/default/,"en")
|
47
|
+
if(!redis_agent[new_key]) then # If nil then assign default value.
|
48
|
+
redis_agent[new_key] = value
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# converting the 1-D hash into xml string.
|
53
|
+
txs = XmlSimple.xml_out(one_dim_hash)
|
54
|
+
|
55
|
+
mechanize_agent = Mechanize.new
|
56
|
+
mechanize_agent.post("#{chronuscop_config[RAILS_ENV]["chronuscop_server_address"]}/projects/#{chronuscop_config[RAILS_ENV]["project_number"]}/translations/add/?auth_token=#{chronuscop_config[RAILS_ENV]["api_token"]}","translations_xml_string" => txs)
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'chronuscop_client'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chronuscop_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 0.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- ajey
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-07-11 00:00:00 +05:30
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ~>
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
segments:
|
26
|
+
- 1
|
27
|
+
- 0
|
28
|
+
- 0
|
29
|
+
version: 1.0.0
|
30
|
+
requirement: *id001
|
31
|
+
prerelease: false
|
32
|
+
type: :runtime
|
33
|
+
name: mechanize
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ~>
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 1
|
41
|
+
- 0
|
42
|
+
- 15
|
43
|
+
version: 1.0.15
|
44
|
+
requirement: *id002
|
45
|
+
prerelease: false
|
46
|
+
type: :runtime
|
47
|
+
name: xml-simple
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 2
|
55
|
+
- 2
|
56
|
+
- 1
|
57
|
+
version: 2.2.1
|
58
|
+
requirement: *id003
|
59
|
+
prerelease: false
|
60
|
+
type: :runtime
|
61
|
+
name: redis
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ~>
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
segments:
|
68
|
+
- 1
|
69
|
+
- 2
|
70
|
+
- 3
|
71
|
+
version: 1.2.3
|
72
|
+
requirement: *id004
|
73
|
+
prerelease: false
|
74
|
+
type: :runtime
|
75
|
+
name: SystemTimer
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ~>
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
segments:
|
82
|
+
- 1
|
83
|
+
- 0
|
84
|
+
- 0
|
85
|
+
version: 1.0.0
|
86
|
+
requirement: *id005
|
87
|
+
prerelease: false
|
88
|
+
type: :development
|
89
|
+
name: bundler
|
90
|
+
- !ruby/object:Gem::Dependency
|
91
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ~>
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
segments:
|
96
|
+
- 1
|
97
|
+
- 6
|
98
|
+
- 2
|
99
|
+
version: 1.6.2
|
100
|
+
requirement: *id006
|
101
|
+
prerelease: false
|
102
|
+
type: :development
|
103
|
+
name: jeweler
|
104
|
+
- !ruby/object:Gem::Dependency
|
105
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
segments:
|
110
|
+
- 0
|
111
|
+
version: "0"
|
112
|
+
requirement: *id007
|
113
|
+
prerelease: false
|
114
|
+
type: :development
|
115
|
+
name: rcov
|
116
|
+
description: This gem helps you to easily tweak your rails app to use the chronuscop server.
|
117
|
+
email: ajey@chronus.com
|
118
|
+
executables: []
|
119
|
+
|
120
|
+
extensions: []
|
121
|
+
|
122
|
+
extra_rdoc_files:
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.rdoc
|
125
|
+
files:
|
126
|
+
- .document
|
127
|
+
- Gemfile
|
128
|
+
- Gemfile.lock
|
129
|
+
- LICENSE.txt
|
130
|
+
- README.rdoc
|
131
|
+
- Rakefile
|
132
|
+
- VERSION
|
133
|
+
- chronuscop_client.gemspec
|
134
|
+
- lib/chronuscop_client.rb
|
135
|
+
- lib/chronuscop_client/chronus_backend.rb
|
136
|
+
- lib/chronuscop_client/configuration.rb
|
137
|
+
- lib/chronuscop_client/railtie.rb
|
138
|
+
- lib/chronuscop_client/synchronizer.rb
|
139
|
+
- lib/tasks/chronuscop_client_tasks.rake
|
140
|
+
- test/helper.rb
|
141
|
+
- test/test_chronuscop_client.rb
|
142
|
+
has_rdoc: true
|
143
|
+
homepage: http://github.com/ajey/chronuscop_client
|
144
|
+
licenses:
|
145
|
+
- MIT
|
146
|
+
post_install_message:
|
147
|
+
rdoc_options: []
|
148
|
+
|
149
|
+
require_paths:
|
150
|
+
- lib
|
151
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
segments:
|
156
|
+
- 0
|
157
|
+
version: "0"
|
158
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
segments:
|
163
|
+
- 0
|
164
|
+
version: "0"
|
165
|
+
requirements: []
|
166
|
+
|
167
|
+
rubyforge_project:
|
168
|
+
rubygems_version: 1.3.6
|
169
|
+
signing_key:
|
170
|
+
specification_version: 3
|
171
|
+
summary: chronuscop_client gem to easily integrate your rails app with the chronuscop server.
|
172
|
+
test_files: []
|
173
|
+
|