mobility 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +19 -0
  3. data/Gemfile.lock +153 -0
  4. data/Guardfile +70 -0
  5. data/README.md +603 -13
  6. data/Rakefile +42 -0
  7. data/lib/generators/mobility/install_generator.rb +45 -0
  8. data/lib/generators/mobility/templates/create_string_translations.rb +15 -0
  9. data/lib/generators/mobility/templates/create_text_translations.rb +15 -0
  10. data/lib/mobility.rb +203 -2
  11. data/lib/mobility/active_model.rb +6 -0
  12. data/lib/mobility/active_model/attribute_methods.rb +27 -0
  13. data/lib/mobility/active_model/backend_resetter.rb +26 -0
  14. data/lib/mobility/active_record.rb +39 -0
  15. data/lib/mobility/active_record/backend_resetter.rb +26 -0
  16. data/lib/mobility/active_record/model_translation.rb +14 -0
  17. data/lib/mobility/active_record/string_translation.rb +7 -0
  18. data/lib/mobility/active_record/text_translation.rb +7 -0
  19. data/lib/mobility/active_record/translation.rb +14 -0
  20. data/lib/mobility/attributes.rb +210 -0
  21. data/lib/mobility/backend.rb +152 -0
  22. data/lib/mobility/backend/active_model.rb +7 -0
  23. data/lib/mobility/backend/active_model/dirty.rb +84 -0
  24. data/lib/mobility/backend/active_record.rb +13 -0
  25. data/lib/mobility/backend/active_record/column.rb +52 -0
  26. data/lib/mobility/backend/active_record/column/query_methods.rb +40 -0
  27. data/lib/mobility/backend/active_record/hash_valued.rb +58 -0
  28. data/lib/mobility/backend/active_record/hstore.rb +36 -0
  29. data/lib/mobility/backend/active_record/hstore/query_methods.rb +53 -0
  30. data/lib/mobility/backend/active_record/jsonb.rb +43 -0
  31. data/lib/mobility/backend/active_record/jsonb/query_methods.rb +53 -0
  32. data/lib/mobility/backend/active_record/key_value.rb +126 -0
  33. data/lib/mobility/backend/active_record/key_value/query_methods.rb +63 -0
  34. data/lib/mobility/backend/active_record/query_methods.rb +36 -0
  35. data/lib/mobility/backend/active_record/serialized.rb +93 -0
  36. data/lib/mobility/backend/active_record/serialized/query_methods.rb +32 -0
  37. data/lib/mobility/backend/active_record/table.rb +197 -0
  38. data/lib/mobility/backend/active_record/table/query_methods.rb +91 -0
  39. data/lib/mobility/backend/cache.rb +110 -0
  40. data/lib/mobility/backend/column.rb +52 -0
  41. data/lib/mobility/backend/dirty.rb +28 -0
  42. data/lib/mobility/backend/fallbacks.rb +89 -0
  43. data/lib/mobility/backend/hstore.rb +21 -0
  44. data/lib/mobility/backend/jsonb.rb +21 -0
  45. data/lib/mobility/backend/key_value.rb +71 -0
  46. data/lib/mobility/backend/null.rb +24 -0
  47. data/lib/mobility/backend/orm_delegator.rb +33 -0
  48. data/lib/mobility/backend/sequel.rb +14 -0
  49. data/lib/mobility/backend/sequel/column.rb +40 -0
  50. data/lib/mobility/backend/sequel/column/query_methods.rb +24 -0
  51. data/lib/mobility/backend/sequel/dirty.rb +54 -0
  52. data/lib/mobility/backend/sequel/hash_valued.rb +51 -0
  53. data/lib/mobility/backend/sequel/hstore.rb +36 -0
  54. data/lib/mobility/backend/sequel/hstore/query_methods.rb +42 -0
  55. data/lib/mobility/backend/sequel/jsonb.rb +43 -0
  56. data/lib/mobility/backend/sequel/jsonb/query_methods.rb +42 -0
  57. data/lib/mobility/backend/sequel/key_value.rb +139 -0
  58. data/lib/mobility/backend/sequel/key_value/query_methods.rb +48 -0
  59. data/lib/mobility/backend/sequel/query_methods.rb +22 -0
  60. data/lib/mobility/backend/sequel/serialized.rb +133 -0
  61. data/lib/mobility/backend/sequel/serialized/query_methods.rb +20 -0
  62. data/lib/mobility/backend/sequel/table.rb +149 -0
  63. data/lib/mobility/backend/sequel/table/query_methods.rb +48 -0
  64. data/lib/mobility/backend/serialized.rb +53 -0
  65. data/lib/mobility/backend/table.rb +93 -0
  66. data/lib/mobility/backend_resetter.rb +44 -0
  67. data/lib/mobility/configuration.rb +31 -0
  68. data/lib/mobility/core_ext/nil.rb +10 -0
  69. data/lib/mobility/core_ext/object.rb +19 -0
  70. data/lib/mobility/core_ext/string.rb +16 -0
  71. data/lib/mobility/instance_methods.rb +34 -0
  72. data/lib/mobility/orm.rb +4 -0
  73. data/lib/mobility/sequel.rb +26 -0
  74. data/lib/mobility/sequel/backend_resetter.rb +26 -0
  75. data/lib/mobility/sequel/column_changes.rb +29 -0
  76. data/lib/mobility/sequel/model_translation.rb +20 -0
  77. data/lib/mobility/sequel/string_translation.rb +7 -0
  78. data/lib/mobility/sequel/text_translation.rb +7 -0
  79. data/lib/mobility/sequel/translation.rb +53 -0
  80. data/lib/mobility/translates.rb +75 -0
  81. data/lib/mobility/wrapper.rb +31 -0
  82. metadata +152 -12
  83. data/.gitignore +0 -9
  84. data/.rspec +0 -2
  85. data/.travis.yml +0 -5
  86. data/bin/console +0 -14
  87. data/bin/setup +0 -8
  88. data/mobility.gemspec +0 -32
@@ -0,0 +1,75 @@
1
+ module Mobility
2
+ =begin
3
+
4
+ Defines methods for attaching backends to a class. A block can optionally be
5
+ passed to accessors to configure backend (see example below).
6
+
7
+ @example Defining backend on a class
8
+ class MyClass
9
+ extend Translates
10
+ mobility_accessor :foo, option1: :value
11
+ end
12
+
13
+ @example Passing backend to a block
14
+ class MyClass
15
+ extend Translates
16
+ mobility_accessor :foo, option1: :value do |backend|
17
+ # do something with backend
18
+ end
19
+ end
20
+
21
+ @example Defining only a backend reader and presence method
22
+ class MyClass
23
+ extend Translates
24
+ mobility_reader :foo
25
+ end
26
+
27
+ instance = MyClass.new
28
+ instance.foo #=> (some value)
29
+ instance.foo? #=> true
30
+ instance.foo = "foo" #=> NoMethodError
31
+
32
+ @example Defining only a backend writer
33
+ class MyClass
34
+ extend Translates
35
+ mobility_writer :foo
36
+ end
37
+
38
+ instance = MyClass.new
39
+ instance.foo #=> NoMethodError
40
+ instance.foo? #=> NoMethodError
41
+ instance.foo = "foo" #=> (sets attribute to value "foo")
42
+ =end
43
+ module Translates
44
+ # Defines mobility accessor on model class.
45
+ # @param [Array<String>] attributes
46
+ # @param [Hash] options
47
+ # @yield [Object] Backend
48
+ # @!method mobility_accessor(*attributes, **options)
49
+
50
+ # Defines mobility reader and presence method on model class.
51
+ # @param [Array<String>] attributes
52
+ # @param [Hash] options
53
+ # @yield [Object] Backend
54
+ # @!method mobility_reader(*attributes, **options)
55
+
56
+ # Defines mobility writer on model class.
57
+ # @param [Array<String>] attributes
58
+ # @param [Hash] options
59
+ # @yield [Object] Backend
60
+ # @!method mobility_writer(*attributes, **options)
61
+ %w[accessor reader writer].each do |method|
62
+ class_eval <<-EOM, __FILE__, __LINE__ + 1
63
+ def mobility_#{method}(*args, **options)
64
+ attributes = Attributes.new(:#{method}, *args, options.merge(model_class: self))
65
+ yield(attributes.backend) if block_given?
66
+ attributes.each do |attribute|
67
+ alias_method "\#{attribute}_before_mobility", attribute if method_defined?(attribute) && #{%w[accessor reader].include? method}
68
+ alias_method "\#{attribute}_before_mobility=", "\#{attribute}=" if method_defined?("\#{attribute}=") && #{%w[accessor writer].include? method}
69
+ end
70
+ include attributes
71
+ end
72
+ EOM
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,31 @@
1
+ module Mobility
2
+ =begin
3
+
4
+ Class to access Mobility across backends. In particular, keeps a record of
5
+ which {Attributes} modules have been included on the model class. It is also a
6
+ simple delegator, so any missing method will be delegated to the model class.
7
+
8
+ =end
9
+ class Wrapper < SimpleDelegator
10
+ # @return [Array<Attributes>]
11
+ attr_reader :modules
12
+ alias :model_class :__getobj__
13
+
14
+ # @param [Class] model_class Model class
15
+ def initialize(model_class)
16
+ super
17
+ @modules = []
18
+ end
19
+
20
+ # @return [Array<String>] Translated attributes defined on model
21
+ def translated_attribute_names
22
+ modules.map(&:attributes).flatten
23
+ end
24
+
25
+ # Appends backend module to +modules+ array for later reference.
26
+ # @param [Attributes] backend_module Attributes module
27
+ def << backend_module
28
+ modules << backend_module
29
+ end
30
+ end
31
+ end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mobility
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Salzberg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-03 00:00:00.000000000 Z
11
+ date: 2017-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: request_store
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: i18n
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.6.10
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.6.10
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: bundler
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +52,20 @@ dependencies:
24
52
  - - "~>"
25
53
  - !ruby/object:Gem::Version
26
54
  version: '1.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: database_cleaner
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.5.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.5.3
27
69
  - !ruby/object:Gem::Dependency
28
70
  name: rake
29
71
  requirement: !ruby/object:Gem::Requirement
@@ -52,25 +94,124 @@ dependencies:
52
94
  - - "~>"
53
95
  - !ruby/object:Gem::Version
54
96
  version: '3.0'
55
- description:
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-its
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.2.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.2.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.9.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.9.0
125
+ description: Stores and retrieves localized data through attributes on a Ruby class,
126
+ with flexible support for different storage strategies.
56
127
  email:
57
128
  - chris@dejimata.com
58
129
  executables: []
59
130
  extensions: []
60
131
  extra_rdoc_files: []
61
132
  files:
62
- - ".gitignore"
63
- - ".rspec"
64
- - ".travis.yml"
65
133
  - Gemfile
134
+ - Gemfile.lock
135
+ - Guardfile
66
136
  - LICENSE.txt
67
137
  - README.md
68
138
  - Rakefile
69
- - bin/console
70
- - bin/setup
139
+ - lib/generators/mobility/install_generator.rb
140
+ - lib/generators/mobility/templates/create_string_translations.rb
141
+ - lib/generators/mobility/templates/create_text_translations.rb
71
142
  - lib/mobility.rb
143
+ - lib/mobility/active_model.rb
144
+ - lib/mobility/active_model/attribute_methods.rb
145
+ - lib/mobility/active_model/backend_resetter.rb
146
+ - lib/mobility/active_record.rb
147
+ - lib/mobility/active_record/backend_resetter.rb
148
+ - lib/mobility/active_record/model_translation.rb
149
+ - lib/mobility/active_record/string_translation.rb
150
+ - lib/mobility/active_record/text_translation.rb
151
+ - lib/mobility/active_record/translation.rb
152
+ - lib/mobility/attributes.rb
153
+ - lib/mobility/backend.rb
154
+ - lib/mobility/backend/active_model.rb
155
+ - lib/mobility/backend/active_model/dirty.rb
156
+ - lib/mobility/backend/active_record.rb
157
+ - lib/mobility/backend/active_record/column.rb
158
+ - lib/mobility/backend/active_record/column/query_methods.rb
159
+ - lib/mobility/backend/active_record/hash_valued.rb
160
+ - lib/mobility/backend/active_record/hstore.rb
161
+ - lib/mobility/backend/active_record/hstore/query_methods.rb
162
+ - lib/mobility/backend/active_record/jsonb.rb
163
+ - lib/mobility/backend/active_record/jsonb/query_methods.rb
164
+ - lib/mobility/backend/active_record/key_value.rb
165
+ - lib/mobility/backend/active_record/key_value/query_methods.rb
166
+ - lib/mobility/backend/active_record/query_methods.rb
167
+ - lib/mobility/backend/active_record/serialized.rb
168
+ - lib/mobility/backend/active_record/serialized/query_methods.rb
169
+ - lib/mobility/backend/active_record/table.rb
170
+ - lib/mobility/backend/active_record/table/query_methods.rb
171
+ - lib/mobility/backend/cache.rb
172
+ - lib/mobility/backend/column.rb
173
+ - lib/mobility/backend/dirty.rb
174
+ - lib/mobility/backend/fallbacks.rb
175
+ - lib/mobility/backend/hstore.rb
176
+ - lib/mobility/backend/jsonb.rb
177
+ - lib/mobility/backend/key_value.rb
178
+ - lib/mobility/backend/null.rb
179
+ - lib/mobility/backend/orm_delegator.rb
180
+ - lib/mobility/backend/sequel.rb
181
+ - lib/mobility/backend/sequel/column.rb
182
+ - lib/mobility/backend/sequel/column/query_methods.rb
183
+ - lib/mobility/backend/sequel/dirty.rb
184
+ - lib/mobility/backend/sequel/hash_valued.rb
185
+ - lib/mobility/backend/sequel/hstore.rb
186
+ - lib/mobility/backend/sequel/hstore/query_methods.rb
187
+ - lib/mobility/backend/sequel/jsonb.rb
188
+ - lib/mobility/backend/sequel/jsonb/query_methods.rb
189
+ - lib/mobility/backend/sequel/key_value.rb
190
+ - lib/mobility/backend/sequel/key_value/query_methods.rb
191
+ - lib/mobility/backend/sequel/query_methods.rb
192
+ - lib/mobility/backend/sequel/serialized.rb
193
+ - lib/mobility/backend/sequel/serialized/query_methods.rb
194
+ - lib/mobility/backend/sequel/table.rb
195
+ - lib/mobility/backend/sequel/table/query_methods.rb
196
+ - lib/mobility/backend/serialized.rb
197
+ - lib/mobility/backend/table.rb
198
+ - lib/mobility/backend_resetter.rb
199
+ - lib/mobility/configuration.rb
200
+ - lib/mobility/core_ext/nil.rb
201
+ - lib/mobility/core_ext/object.rb
202
+ - lib/mobility/core_ext/string.rb
203
+ - lib/mobility/instance_methods.rb
204
+ - lib/mobility/orm.rb
205
+ - lib/mobility/sequel.rb
206
+ - lib/mobility/sequel/backend_resetter.rb
207
+ - lib/mobility/sequel/column_changes.rb
208
+ - lib/mobility/sequel/model_translation.rb
209
+ - lib/mobility/sequel/string_translation.rb
210
+ - lib/mobility/sequel/text_translation.rb
211
+ - lib/mobility/sequel/translation.rb
212
+ - lib/mobility/translates.rb
72
213
  - lib/mobility/version.rb
73
- - mobility.gemspec
214
+ - lib/mobility/wrapper.rb
74
215
  homepage:
75
216
  licenses:
76
217
  - MIT
@@ -83,7 +224,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
83
224
  requirements:
84
225
  - - ">="
85
226
  - !ruby/object:Gem::Version
86
- version: '0'
227
+ version: 2.0.0
87
228
  required_rubygems_version: !ruby/object:Gem::Requirement
88
229
  requirements:
89
230
  - - ">="
@@ -94,6 +235,5 @@ rubyforge_project:
94
235
  rubygems_version: 2.4.5.1
95
236
  signing_key:
96
237
  specification_version: 4
97
- summary: Pluggable translation framework for Ruby on Rails.
238
+ summary: Pluggable Ruby translation framework
98
239
  test_files: []
99
- has_rdoc:
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --format documentation
2
- --color
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.2.3
5
- before_install: gem install bundler -v 1.12.5
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "mobility"
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 DELETED
@@ -1,8 +0,0 @@
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
data/mobility.gemspec DELETED
@@ -1,32 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'mobility/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "mobility"
8
- spec.version = "0.0.1"
9
- spec.authors = ["Chris Salzberg"]
10
- spec.email = ["chris@dejimata.com"]
11
-
12
- spec.summary = %q{Pluggable translation framework for Ruby on Rails.}
13
- # spec.homepage = "TODO: Put your gem's website or public repo URL here."
14
- spec.license = "MIT"
15
-
16
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
- # to allow pushing to a single host or delete this section to allow pushing to any host.
18
- if spec.respond_to?(:metadata)
19
- # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
- else
21
- raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
- end
23
-
24
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
- spec.bindir = "exe"
26
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
- spec.require_paths = ["lib"]
28
-
29
- spec.add_development_dependency "bundler", "~> 1.12"
30
- spec.add_development_dependency "rake", "~> 10.0"
31
- spec.add_development_dependency "rspec", "~> 3.0"
32
- end