trexrb 0.1.0

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: a2e7466f0ae48623f28f020285ff34eb0f3ebce8
4
+ data.tar.gz: 32aa5713cab8237066bcb13feb97436cd09c5f46
5
+ SHA512:
6
+ metadata.gz: 3cafaedd8efa8ea382e97c32a2f8f580b0c4577a4eaa827b9cbedd333de1640a76a1fe068071fa05884789094197ad8ee99c9442894633f91ff656b683cfd01a
7
+ data.tar.gz: 0183cb43d24f51cff81236aaf10740e5c7a6ef6bc5bda8e5e8092dc26c5c6032c7f3b3f7b28f3585602e6a7face17ac4b635f71cf5cfe23d24efd91c76a24077
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in trexrb.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Ignacy Moryc
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Trexrb
2
+
3
+ Client library for Trex: I18n storage writen in Elixir
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'trexrb'
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ruby
16
+
17
+ # this probably goes into an initializer
18
+ I18n.backend = Trex::Backend.new
19
+ I18n.available_locales = :en
20
+
21
+ # .. and then it can be used through rails
22
+ I18n.backend.store_translations :en, :foo => { :bar => :baz }
23
+ puts I18n.t "foo" #=> { :bar => :baz }
24
+
25
+ ```
26
+
27
+
28
+ ## License
29
+
30
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "trexrb"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,11 @@
1
+ require 'rails-i18n'
2
+
3
+ module Trexrb
4
+ class Backend < I18n::Backend::KeyValue
5
+ include I18n::Backend::Memoize
6
+
7
+ def initialize
8
+ super(Trexrb.store)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,83 @@
1
+ module Trexrb
2
+ class Storage
3
+ DEFAULT_HOST = 'localhost'
4
+ DEFAULT_PORT = 4040
5
+
6
+ def initialize(host = nil, port = nil)
7
+ @host = host || DEFAULT_HOST
8
+ @port = port || DEFAULT_PORT
9
+ end
10
+
11
+ def get(key)
12
+ with_connection { |conn| conn.print Request.new.get(key) }
13
+ end
14
+
15
+ def set(key, value)
16
+ with_connection { |conn| conn.print Request.new.set(key, value) }
17
+ end
18
+
19
+ def keys
20
+ with_connection { |conn| conn.print Request.new.list }
21
+ end
22
+
23
+ alias_method :[], :get
24
+ alias_method :[]=, :set
25
+
26
+ private
27
+
28
+ attr_reader :host, :port
29
+
30
+ def with_connection
31
+ socket = Socket.tcp(host, port)
32
+ yield socket
33
+ rescue => ex
34
+ puts "Connection error: #{ex.inspect}"
35
+ ensure
36
+ socket.close_write
37
+ return Response.new(socket.read).body
38
+ end
39
+
40
+ Response = Struct.new(:data) do
41
+ def body
42
+ return "{}" if no_data?
43
+ YAML.load(cleaned_data)
44
+ rescue => ex
45
+ puts ex.inspect
46
+ cleaned_data
47
+ end
48
+
49
+ private
50
+
51
+ def no_data?
52
+ data.to_s.strip.length == 0
53
+ end
54
+
55
+ def cleaned_data
56
+ data.rstrip
57
+ end
58
+ end
59
+
60
+ Request = Class.new do
61
+ FIELD_SEPARATOR = "\t"
62
+ TERMINATOR = "\r\n"
63
+
64
+ def get(key)
65
+ build("GET", key)
66
+ end
67
+
68
+ def set(key, value)
69
+ build("SET", key, YAML.dump(value))
70
+ end
71
+
72
+ def list
73
+ build("LIST")
74
+ end
75
+
76
+ private
77
+
78
+ def build(command_name, *params)
79
+ ([command_name] + params).join(FIELD_SEPARATOR) + TERMINATOR
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,3 @@
1
+ module Trexrb
2
+ VERSION = "0.1.0"
3
+ end
data/lib/trexrb.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "trexrb/version"
2
+ require "trexrb/storage"
3
+ require "trexrb/backend"
4
+
5
+ module Trexrb
6
+ def self.store
7
+ @store ||= Storage.new
8
+ end
9
+ end
data/trexrb.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'trexrb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "trexrb"
8
+ spec.version = Trexrb::VERSION
9
+ spec.authors = ["Ignacy Moryc", "Michał Darda"]
10
+ spec.email = ["imoryc@gmail.com", "michal.darda@gmail.com"]
11
+
12
+ spec.summary = %q{Client library for trex I18n store}
13
+ spec.homepage = "https://github.com/ignacy/trexrb"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.11"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_development_dependency "rails-i18n", '~> 4.0.0'
25
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trexrb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ignacy Moryc
8
+ - Michał Darda
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2016-04-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.11'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.11'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '3.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '3.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rails-i18n
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 4.0.0
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 4.0.0
70
+ description:
71
+ email:
72
+ - imoryc@gmail.com
73
+ - michal.darda@gmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - lib/trexrb.rb
87
+ - lib/trexrb/backend.rb
88
+ - lib/trexrb/storage.rb
89
+ - lib/trexrb/version.rb
90
+ - trexrb.gemspec
91
+ homepage: https://github.com/ignacy/trexrb
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.4.5
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Client library for trex I18n store
115
+ test_files: []