aigu-rails 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: a2d1139d62ebf693d079e2d332c7059b3efefe2c
4
+ data.tar.gz: 80fd257afe16c0e5344c816fabd8a7978bf731d3
5
+ SHA512:
6
+ metadata.gz: daf28ee684772ae40b65eb7a60651cc6614cde7d8736b700b9abc5b42982f677f3b281c2690d3a41404a97189eaa38457ff3d0aa4c6953506424d3bd4ab46943
7
+ data.tar.gz: 1b646a3c572f789724d0b23b47b5e503b9e309c962c92215f323f6894a1f62eef7417f05b5115b9f1399cacc2cb5939df06dd4073314ec316cddf9554cb209c1
data/.gitignore ADDED
@@ -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
+ --colour
data/.rubocop.yml ADDED
@@ -0,0 +1,53 @@
1
+ AllCops:
2
+ Include:
3
+ - foo.gemspec
4
+
5
+ Documentation:
6
+ Enabled: false
7
+
8
+ Encoding:
9
+ Enabled: false
10
+
11
+ LineLength:
12
+ Max: 200
13
+
14
+ ClassLength:
15
+ Max: 200
16
+
17
+ AccessModifierIndentation:
18
+ EnforcedStyle: outdent
19
+
20
+ IfUnlessModifier:
21
+ Enabled: false
22
+
23
+ CaseIndentation:
24
+ IndentWhenRelativeTo: case
25
+ IndentOneStep: true
26
+
27
+ MethodLength:
28
+ CountComments: false
29
+ Max: 20
30
+
31
+ SignalException:
32
+ Enabled: false
33
+
34
+ ColonMethodCall:
35
+ Enabled: false
36
+
37
+ AsciiComments:
38
+ Enabled: false
39
+
40
+ Lambda:
41
+ Enabled: false
42
+
43
+ RegexpLiteral:
44
+ Enabled: false
45
+
46
+ AssignmentInCondition:
47
+ Enabled: false
48
+
49
+ ClassAndModuleChildren:
50
+ Enabled: false
51
+
52
+ GuardClause:
53
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.2
5
+ - 2.1
6
+
7
+ script: "echo 'DO IT' && bundle exec rake spec"
8
+
9
+ notifications:
10
+ hipchat:
11
+ rooms:
12
+ secure: cJWiEh3XNWrEkoeaZd5Kyx3igwOJto+B8jPiyr38Kfv8Z2WLINkHbMQXcd37/tIubX6w9VWjWJ2TuX5cK2H07EraPDDYAHJlnoR/WIPoYwQoXGUWqGH26O2LdBiLs9JcBQ9rKT8K8wmQuxf2rTpY7lN2RoKMjjEjcleWJwQG/3w=
13
+ template:
14
+ - '%{repository}#%{build_number} (%{branch} - %{commit} : %{author}): %{message} (<a href="%{build_url}">Build</a>/<a href="%{compare_url}">Changes</a>)'
15
+ format: 'html'
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2015, Mirego
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ - Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ - Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ - Neither the name of the Mirego nor the names of its contributors may
13
+ be used to endorse or promote products derived from this software without
14
+ specific prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
+ POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ <p align="center">
2
+ <a href="https://github.com/mirego/aigu-rails"><strong>AiguRails</strong></a>
3
+ <br />
4
+ Add support for Rails locales with aigu
5
+ <br /><br />
6
+ <a href="https://rubygems.org/gems/aigu-rails"><img src="http://img.shields.io/gem/v/foo.svg" /></a>
7
+ <a href="https://codeclimate.com/github/mirego/aigu-rails"><img src="http://img.shields.io/codeclimate/github/mirego/foo.svg" /></a>
8
+ <a href='https://gemnasium.com/mirego/aigu-rails'><img src="http://img.shields.io/gemnasium/mirego/foo.svg" /></a>
9
+ <a href="https://travis-ci.org/mirego/aigu-rails"><img src="http://img.shields.io/travis/mirego/foo.svg" /></a>
10
+ </p>
11
+
12
+ ---
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'aigu-rails'
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ Configure the api key.
25
+
26
+ ```ruby
27
+ Aigu::Rails.configure do |config|
28
+ config.api_key = 'YOUR API KEY'
29
+ end
30
+ ```
31
+
32
+ ```ruby
33
+ Aigu::Rails.reload_locales!(locale: :fr)
34
+ ```
35
+
36
+ ## License
37
+
38
+ `aigu-rails` is © 2015 [Mirego](http://www.mirego.com) and may be freely distributed under the [New BSD license](http://opensource.org/licenses/BSD-3-Clause). See the [`LICENSE.md`](https://github.com/mirego/foo/blob/master/LICENSE.md) file.
39
+
40
+ ## About Mirego
41
+
42
+ [Mirego](http://mirego.com) is a team of passionate people who believe that work is a place where you can innovate and have fun. We're a team of [talented people](http://life.mirego.com) who imagine and build beautiful Web and mobile applications. We come together to share ideas and [change the world](http://mirego.org).
43
+
44
+ We also [love open-source software](http://open.mirego.com) and we try to give back to the community as much as we can.
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'bundler'
2
+ require 'rake'
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ task default: :spec
7
+
8
+ desc 'Run all specs'
9
+ RSpec::Core::RakeTask.new(:spec) do |task|
10
+ task.pattern = 'spec/**/*_spec.rb'
11
+ end
12
+
13
+ desc 'Start an IRB session with the gem'
14
+ task :console do
15
+ $:.unshift File.expand_path('..', __FILE__)
16
+ require 'foo'
17
+ require 'irb'
18
+
19
+ ARGV.clear
20
+ IRB.start
21
+ 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 'aigu-rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'aigu-rails'
8
+ spec.version = Aigu::Rails::VERSION
9
+ spec.authors = ['Samuel Garneau']
10
+ spec.email = ['sgarneau@mirego.com']
11
+ spec.description = 'Add support for Rails locales with aigu'
12
+ spec.summary = spec.description
13
+ spec.homepage = 'https://github.com/mirego/foo'
14
+ spec.license = 'BSD 3-Clause'
15
+
16
+ spec.files = `git ls-files`.split($RS)
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_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake', '~> 10.4'
23
+ spec.add_development_dependency 'rspec', '~> 3.2'
24
+ spec.add_development_dependency 'rubocop', '~> 0.31'
25
+ spec.add_development_dependency 'phare', '~> 0.7'
26
+ end
@@ -0,0 +1,44 @@
1
+ module Aigu
2
+ module Rails
3
+ module Accent
4
+ class LocaleDownloader
5
+ def initialize(locale:)
6
+ @locale = locale
7
+ end
8
+
9
+ def download!
10
+ File.open(input_filename, 'w') do |file|
11
+ file.write(parsed_response)
12
+ end
13
+ end
14
+
15
+ protected
16
+
17
+ def parsed_response
18
+ JSON.parse(response.body).to_json
19
+ end
20
+
21
+ def input_filename
22
+ "#{::Rails.root}/tmp/locales.json"
23
+ end
24
+
25
+ def api_key
26
+ Aigu::Rails.configuration.api_key
27
+ end
28
+
29
+ def response
30
+ path = "/public_api/latest_revision?language=#{@locale}&render_format=json&render_filename=locales.json"
31
+ uri = URI.parse('https://accent.mirego.com')
32
+
33
+ http = Net::HTTP.new(uri.host, uri.port)
34
+ http.use_ssl = true
35
+
36
+ req = Net::HTTP::Get.new(uri.path + path)
37
+ req['Authorization'] = api_key
38
+
39
+ http.request(req)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,29 @@
1
+ module Aigu
2
+ module Rails
3
+ module Accent
4
+ class LocaleImporter
5
+ def initialize(locale:)
6
+ @locale = locale
7
+ end
8
+
9
+ def import!
10
+ Aigu::Importer.new(
11
+ :'input-file' => input_filename,
12
+ :'output-directory' => output_directory,
13
+ :'locale' => @locale
14
+ ).process!
15
+ end
16
+
17
+ protected
18
+
19
+ def input_filename
20
+ "#{::Rails.root}/tmp/locales.json"
21
+ end
22
+
23
+ def output_directory
24
+ "#{::Rails.root}/config/locales/"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,32 @@
1
+ module Aigu
2
+ module Rails
3
+ module Accent
4
+ class LocaleReloader
5
+ def initialize(locale:)
6
+ @locale = locale
7
+ end
8
+
9
+ def reload!
10
+ # Download the file from Accent
11
+ downloader.download!
12
+
13
+ # Process the file with aigu
14
+ importer.import!
15
+
16
+ # Reload Rails locales
17
+ I18n.reload!
18
+ end
19
+
20
+ protected
21
+
22
+ def downloader
23
+ LocaleDownloader.new(locale: @locale)
24
+ end
25
+
26
+ def importer
27
+ LocaleImporter.new(locale: @locale)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,10 @@
1
+ require_relative 'accent/locale_downloader'
2
+ require_relative 'accent/locale_importer'
3
+ require_relative 'accent/locale_reloader'
4
+
5
+ module Aigu
6
+ module Rails
7
+ module Accent
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ module Aigu
2
+ module Rails
3
+ VERSION = '0.1'
4
+ end
5
+ end
data/lib/aigu-rails.rb ADDED
@@ -0,0 +1,24 @@
1
+ # Dependencies
2
+ require 'ostruct'
3
+
4
+ # Services
5
+ require 'aigu-rails/accent'
6
+
7
+ # Version
8
+ require 'aigu-rails/version'
9
+
10
+ module Aigu
11
+ module Rails
12
+ def self.configure
13
+ yield(self.configuration)
14
+ end
15
+
16
+ def self.configuration
17
+ @configuration ||= OpenStruct.new
18
+ end
19
+
20
+ def self.reload_locales!(locale:)
21
+ Accent::LocaleReloader.new(locale: locale).reload!
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Aigu::Rails do
4
+ let(:base_class) { Aigu::Rails }
5
+
6
+ describe :configure do
7
+ let(:api_key) { '1ee7' }
8
+
9
+ specify do
10
+ base_class.configure do |config|
11
+ config.api_key = api_key
12
+ end
13
+
14
+ expect(base_class.configuration.api_key).to eq(api_key)
15
+ end
16
+ end
17
+
18
+ describe :reload_locales! do
19
+ let(:locale_reloader) { instance_double('Aigu::Rails::Accent::LocaleReloader') }
20
+ let(:locale) { 'fr' }
21
+
22
+ before do
23
+ expect(Aigu::Rails::Accent::LocaleReloader).to receive(:new).with(locale: locale).and_return(locale_reloader)
24
+ expect(locale_reloader).to receive(:reload!)
25
+ end
26
+
27
+ specify { base_class.reload_locales!(locale: locale) }
28
+ end
29
+ end
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
+
3
+ # Test dependencies
4
+ require 'rspec'
5
+
6
+ # Gem
7
+ require 'aigu-rails'
8
+
9
+ RSpec.configure do |config|
10
+ # Disable `should` syntax
11
+ config.expect_with :rspec do |c|
12
+ c.syntax = :expect
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aigu-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Samuel Garneau
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.31'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.31'
69
+ - !ruby/object:Gem::Dependency
70
+ name: phare
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.7'
83
+ description: Add support for Rails locales with aigu
84
+ email:
85
+ - sgarneau@mirego.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".rubocop.yml"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE.md
96
+ - README.md
97
+ - Rakefile
98
+ - aigu-rails.gemspec
99
+ - lib/aigu-rails.rb
100
+ - lib/aigu-rails/accent.rb
101
+ - lib/aigu-rails/accent/locale_downloader.rb
102
+ - lib/aigu-rails/accent/locale_importer.rb
103
+ - lib/aigu-rails/accent/locale_reloader.rb
104
+ - lib/aigu-rails/version.rb
105
+ - spec/aigu_rails_spec.rb
106
+ - spec/spec_helper.rb
107
+ homepage: https://github.com/mirego/foo
108
+ licenses:
109
+ - BSD 3-Clause
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.4.5
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Add support for Rails locales with aigu
131
+ test_files:
132
+ - spec/aigu_rails_spec.rb
133
+ - spec/spec_helper.rb