i18n-mongodb 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9dbf33bd65995b1369c5da6bf7ad514173b171f9
4
+ data.tar.gz: 8ce7db6d38f8a9a4b2607447bcad353fc28e9957
5
+ SHA512:
6
+ metadata.gz: 4fbc7995ff11c086f029f08132efb7c52bc855e9493189ed99d92b801158c49fc5fcfe0897b98aa7d027a1a5e4cb943de26201c4f9d2096507757938a45e17c4
7
+ data.tar.gz: b33ffad3c2c592cc4cea876d2d345ba303b2d13ed9574feb0f3005f12d1f104fd90c09e095625babca924c7ae47978d087673bd1cce5542fd68a8ceee70feac1
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .ruby-*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in i18n-mongodb.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 antonio lorusso
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Antonio Lorusso
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # I18n::Mongodb
2
+
3
+ a simple Rails I18n backend using MongoDB
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'i18n-mongodb'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install i18n-mongodb
18
+
19
+ ## Usage
20
+
21
+ Create an initializer `config/initializers/i18n_backend.rb` and copy/adjust the code below:
22
+
23
+ ```ruby
24
+ require 'i18n/backend/mongodb'
25
+
26
+ session = Moped::Session.new(["127.0.0.1:27017"]).use(:i18n)
27
+ collection = session[:translations]
28
+ I18n.backend = I18n::Backend::Mongodb.new(collection)
29
+ ```
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( http://github.com/zekus/i18n-mongodb/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ task :default => [:test]
6
+
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << 'lib'
9
+ t.libs << 'test'
10
+ t.pattern = "#{File.dirname(__FILE__)}/test/*_test.rb"
11
+ t.verbose = true
12
+ t.warning = false
13
+ end
14
+ Rake::Task['test'].comment = "Run mongo i18n tests"
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'i18n/mongodb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "i18n-mongodb"
8
+ spec.version = I18n::Mongodb::VERSION
9
+ spec.authors = ["Antonio Lorusso"]
10
+ spec.email = ["antonio.lorusso@gmail.com"]
11
+ spec.summary = %q{Rails I18n backend for MongoDB}
12
+ spec.description = %q{Rails I18n backend for MongoDB}
13
+ spec.homepage = "http://antoniolorusso.com/i18n-mongodb"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.platform = Gem::Platform::RUBY
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "i18n"
23
+ spec.add_dependency "moped", "~> 2.0.beta6"
24
+ spec.add_development_dependency "bundler", "~> 1.5"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "mocha"
27
+ spec.add_development_dependency "test_declarative"
28
+ spec.add_development_dependency "turn"
29
+ end
@@ -0,0 +1,36 @@
1
+ require 'i18n'
2
+
3
+ module I18n
4
+ module Backend
5
+ class Mongodb
6
+ include Base, Flatten
7
+
8
+ attr_accessor :collection
9
+
10
+ def initialize(collection, subtrees = true)
11
+ @collection, @subtrees = collection, subtrees
12
+ collection.indexes.create({key: 1, locale: 1}, {unique: true})
13
+ end
14
+
15
+ def store_translations(locale, data, options={})
16
+ escape = options.fetch(:escape, true)
17
+ flatten_translations(locale, data, escape, @subtrees).each do |key, value|
18
+ collection.find(key: key.to_s, locale: locale.to_s).upsert('$set' => { value: value })
19
+ end
20
+ end
21
+
22
+ def available_locales
23
+ collection.find.distinct(:locale).map(&:to_sym)
24
+ end
25
+
26
+ protected
27
+
28
+ def lookup(locale, key, scope=[], options={})
29
+ key = normalize_flat_keys(locale, key, scope, options[:separator])
30
+ value = collection.find(key: key.to_s, locale: locale.to_s).select(_id: 0, value: 1).first
31
+ value = value[:value] unless value.nil?
32
+ value.is_a?(Hash) ? value.deep_symbolize_keys : value
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,7 @@
1
+ require "i18n/mongodb/version"
2
+
3
+ module I18n
4
+ module Mongodb
5
+ # Your code goes here...
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module I18n
2
+ module Mongodb
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,40 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+ require 'i18n/tests'
3
+ require 'i18n/backend/mongodb'
4
+ require 'moped'
5
+
6
+ class I18nMongodbTest < Test::Unit::TestCase
7
+ def setup
8
+ session = Moped::Session.new(["127.0.0.1:27017"])
9
+ session.use('test')
10
+ @collection = session[:translations]
11
+ I18n.backend = I18n::Backend::Mongodb.new(@collection)
12
+ super
13
+ end
14
+
15
+ def teardown
16
+ @collection.drop
17
+ super
18
+ end
19
+
20
+ test "make sure we use a MongoDB backend" do
21
+ assert_equal I18n::Backend::Mongodb, I18n.backend.class
22
+ end
23
+
24
+ def self.can_store_procs?
25
+ false
26
+ end
27
+
28
+ include I18n::Tests::Basics
29
+ include I18n::Tests::Defaults
30
+ include I18n::Tests::Interpolation
31
+ include I18n::Tests::Link
32
+ include I18n::Tests::Lookup
33
+ include I18n::Tests::Pluralization
34
+ include I18n::Tests::Procs if cae_store_procs?
35
+
36
+ include I18n::Tests::Localization::Date
37
+ include I18n::Tests::Localization::DateTime
38
+ include I18n::Tests::Localization::Time
39
+ include I18n::Tests::Localization::Procs if can_store_procs?
40
+ end
@@ -0,0 +1,54 @@
1
+ $:.unshift File.expand_path("../lib", File.dirname(__FILE__))
2
+ require 'test/unit'
3
+ require 'test_declarative'
4
+ require 'i18n'
5
+ require 'i18n/tests'
6
+ require 'mocha/test_unit'
7
+ require 'turn/autorun'
8
+
9
+ class Test::Unit::TestCase
10
+ def self.test(name, &block)
11
+ test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
12
+ defined = instance_method(test_name) rescue false
13
+ raise "#{test_name} is already defined in #{self}" if defined
14
+ if block_given?
15
+ define_method(test_name, &block)
16
+ else
17
+ define_method(test_name) do
18
+ flunk "No implementation provided for #{name}"
19
+ end
20
+ end
21
+ end
22
+
23
+ def self.with_mocha
24
+ yield if Object.respond_to?(:expects)
25
+ end
26
+
27
+ def teardown
28
+ I18n.locale = nil
29
+ I18n.default_locale = :en
30
+ I18n.load_path = []
31
+ I18n.available_locales = nil
32
+ I18n.backend = nil
33
+ end
34
+
35
+ def translations
36
+ I18n.backend.instance_variable_get(:@translations)
37
+ end
38
+
39
+ def store_translations(*args)
40
+ data = args.pop
41
+ locale = args.pop || :en
42
+ I18n.backend.store_translations(locale, data)
43
+ end
44
+
45
+ def locales_dir
46
+ File.dirname(__FILE__) + '/test_data/locales'
47
+ end
48
+ end
49
+
50
+ Object.class_eval do
51
+ def meta_class
52
+ class << self; self; end
53
+ end
54
+ end unless Object.method_defined?(:meta_class)
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: i18n-mongodb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Antonio Lorusso
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: i18n
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: moped
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.beta6
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.beta6
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: test_declarative
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: turn
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Rails I18n backend for MongoDB
112
+ email:
113
+ - antonio.lorusso@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - Gemfile
120
+ - LICENSE
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - i18n-mongodb.gemspec
125
+ - lib/i18n/backend/mongodb.rb
126
+ - lib/i18n/mongodb.rb
127
+ - lib/i18n/mongodb/version.rb
128
+ - test/mongodb_test.rb
129
+ - test/test_helper.rb
130
+ homepage: http://antoniolorusso.com/i18n-mongodb
131
+ licenses:
132
+ - MIT
133
+ metadata: {}
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 2.2.2
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: Rails I18n backend for MongoDB
154
+ test_files:
155
+ - test/mongodb_test.rb
156
+ - test/test_helper.rb