mopper 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
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
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Andrey Eremin
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.
@@ -0,0 +1,64 @@
1
+ # Mopper
2
+
3
+ Import translations for table from SCV file using Globalize3
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'mopper'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install mopper
18
+
19
+ ## Usage
20
+
21
+ Mopper adds `import_translations` class method on any model.
22
+
23
+ You need to have a csv file in UTF-8 with `;` as columns separator with at least 2 columns: first with object id, second with translated data for the object
24
+
25
+ Then you need to pass 3 arguments to Mopper's method:
26
+
27
+ * locale - locale name for importing translations
28
+ * fileds - array of fields for translation table
29
+ * file_path - path to *.csv file
30
+
31
+ ```ruby
32
+
33
+ class ImportPersonTranslates < ActiveRecord::Migration
34
+ def up
35
+ Person.import_translations locale: :en, fields: [:name], file_path: Rails.root.join('db', 'import', 'import.csv')
36
+ end
37
+ end
38
+
39
+ ```
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
48
+
49
+ ## Licence
50
+
51
+ This code is [MIT][mit] licenced:
52
+
53
+ Copyright (c) 2013 Eremin Andrey
54
+
55
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
56
+
57
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
58
+
59
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
60
+
61
+
62
+ [mit]: http://www.opensource.org/licenses/mit-license.php
63
+ [murmur]: http://en.wikipedia.org/wiki/MurmurHash
64
+ [research]: https://panopticlick.eff.org/browser-uniqueness.pdf
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+
6
+ task(default: :spec)
@@ -0,0 +1,6 @@
1
+ require "mopper/version"
2
+ require 'globalize3'
3
+ require 'csv'
4
+ require "mopper/translations"
5
+
6
+ ActiveRecord::Base.extend Mopper::Translations
@@ -0,0 +1,22 @@
1
+ module Mopper
2
+ module Translations
3
+
4
+ def import_translations(args)
5
+ raise ArgumentError unless args[:file_path] && args[:locale] && args[:fields]
6
+ data = CSV.read(args[:file_path], { :col_sep => ';', :encoding => 'UTF-8' })
7
+
8
+ return false unless data.size
9
+
10
+ data.each_with_index do |row, i|
11
+ obj = self.where(:id => row[0]).first
12
+ next unless obj
13
+ args[:fields].each_with_index do |f, n|
14
+ obj.write_attribute(f.to_sym, row[n+1], locale: args[:locale].to_sym)
15
+ end
16
+ obj.save!
17
+ end
18
+ true
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module Mopper
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mopper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mopper"
8
+ spec.version = Mopper::VERSION
9
+ spec.authors = ["Andrey Eremin"]
10
+ spec.email = ["dsoft88@gmail.com"]
11
+ spec.description = %q{Import translations for Model from SCV file using Globalize3}
12
+ spec.summary = %q{Import translations for Model from SCV file using Globalize3}
13
+ spec.homepage = "https://github.com/developer88/mopper"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "activerecord", "~>3.0"
22
+ spec.add_dependency "globalize3", "~>0.3.0"
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec", "~> 2.9"
26
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'mopper' do
4
+ it 'should return version' do
5
+ Mopper::VERSION.should_not be_nil
6
+ end
7
+
8
+ it 'should extend any ActiveRecord models with import_translations class method' do
9
+ class MyModel < ActiveRecord::Base
10
+ end
11
+
12
+ ->{MyModel.send(:import_translations)}.should_not raise_error NoMethodError
13
+ end
14
+
15
+ it 'should raise an error if not all arguments were passed in' do
16
+ class MyModel < ActiveRecord::Base
17
+ end
18
+
19
+ ->{MyModel.send(:import_translations, {locale: :en})}.should raise_error ArgumentError
20
+ end
21
+
22
+ it 'should return false if csv file is empty' do
23
+ class MyModel < ActiveRecord::Base
24
+ end
25
+
26
+ CSV.stub(:read) { [] }
27
+
28
+ MyModel.send(:import_translations, {locale: :en, fields: [:name, :description], file_path:'/usr/test.csv'}).should be_true
29
+ end
30
+
31
+ end
@@ -0,0 +1,5 @@
1
+ require 'bundler/setup'
2
+
3
+ require 'active_record'
4
+ require 'csv'
5
+ require 'mopper'
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mopper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrey Eremin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activerecord
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: globalize3
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.3.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.3.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.3'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '2.9'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '2.9'
94
+ description: Import translations for Model from SCV file using Globalize3
95
+ email:
96
+ - dsoft88@gmail.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - .rspec
103
+ - Gemfile
104
+ - LICENSE.txt
105
+ - README.md
106
+ - Rakefile
107
+ - lib/mopper.rb
108
+ - lib/mopper/translations.rb
109
+ - lib/mopper/version.rb
110
+ - mopper.gemspec
111
+ - spec/mopper_spec.rb
112
+ - spec/spec_helper.rb
113
+ homepage: https://github.com/developer88/mopper
114
+ licenses:
115
+ - MIT
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 1.8.24
135
+ signing_key:
136
+ specification_version: 3
137
+ summary: Import translations for Model from SCV file using Globalize3
138
+ test_files:
139
+ - spec/mopper_spec.rb
140
+ - spec/spec_helper.rb
141
+ has_rdoc: