awesome_hstore_translate 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e1507753d2fc2b2f245bb5722a3cceb79ed0c60e
4
- data.tar.gz: 2da9d49266a0fc17aebd8867c0fc4eda7cb85ff0
2
+ SHA256:
3
+ metadata.gz: 16b8c1361f264ebe2a857e13c237e02b4fd8a48f503a504ea57b1733b455b08f
4
+ data.tar.gz: 158506c34f32c0c5c071a53f6d2591a06b8858300648c3137a00aadc6a16832f
5
5
  SHA512:
6
- metadata.gz: 5dd3a84f1cbb80fb63bfead836712feffd482c7f910e060c33fff61b5436872a5a1283f328ba235887d848cce4eb8bd7a66d7d277960c766fc89bfcd153e4717
7
- data.tar.gz: 546ca2b7728a83aec469eb6442369506aa842e9c2615918a177c382bbfcd4867c963bfe0aeae150f01e0554d449b044740db4dfe3298a33cfe433ba4b5e829d8
6
+ metadata.gz: 24bc81efa70e1275cc03d128110bc92073198d5296dd024b57e3e914968228ddbdfae77bc68e1e5758e8bf2ef2b69f45533a460490f4017489b028ec6d9446e8
7
+ data.tar.gz: 80fe0a1cc9e66f17c7c08d0fd4db5ddb6ee18757604b6ba19d1e23afbae85515da8d93ec01d1a490272e3e554f6e73eb8cd90e75217f4df2f5b04e534a0a1516
@@ -0,0 +1,14 @@
1
+ # [Choice] Ruby version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.0, 2, 2.7, 2.6, 3-bullseye, 3.0-bullseye, 2-bullseye, 2.7-bullseye, 2.6-bullseye, 3-buster, 3.0-buster, 2-buster, 2.7-buster, 2.6-buster
2
+ ARG VARIANT=2-bullseye
3
+ FROM mcr.microsoft.com/vscode/devcontainers/ruby:0-${VARIANT}
4
+
5
+
6
+ # [Optional] Uncomment this section to install additional OS packages.
7
+ # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
8
+ # && apt-get -y install --no-install-recommends <your-package-list-here>
9
+
10
+ # [Optional] Uncomment this line to install additional gems.
11
+ # RUN gem install <your-gem-names-here>
12
+
13
+ # [Optional] Uncomment this line to install global node packages.
14
+ # RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
@@ -0,0 +1,42 @@
1
+ // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2
+ // https://github.com/microsoft/vscode-dev-containers/tree/v0.202.5/containers/ruby-rails-postgres
3
+ // Update the VARIANT arg in docker-compose.yml to pick a Ruby version
4
+ {
5
+ "name": "Awesome Hstore Translate",
6
+ "dockerComposeFile": "docker-compose.yml",
7
+ "service": "app",
8
+ "workspaceFolder": "/workspace",
9
+
10
+ // Set *default* container specific settings.json values on container create.
11
+ "settings": {
12
+ "sqltools.connections": [
13
+ {
14
+ "name": "Test Database",
15
+ "driver": "PostgreSQL",
16
+ "previewLimit": 50,
17
+ "server": "localhost",
18
+ "port": 5432,
19
+
20
+ // update this to match config/database.yml
21
+ "database": "postgres",
22
+ "username": "postgres"
23
+ }
24
+ ]
25
+ },
26
+
27
+ // Add the IDs of extensions you want installed when the container is created.
28
+ "extensions": [
29
+ "rebornix.Ruby",
30
+ "mtxr.sqltools",
31
+ "mtxr.sqltools-driver-pg"
32
+ ],
33
+
34
+ // Use 'forwardPorts' to make a list of ports inside the container available locally.
35
+ // "forwardPorts": [3000, 5432],
36
+
37
+ // Use 'postCreateCommand' to run commands after the container is created.
38
+ // "postCreateCommand": "bundle install && rake db:setup",
39
+
40
+ // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
41
+ //"remoteUser": "vscode"
42
+ }
@@ -0,0 +1,41 @@
1
+ version: '3'
2
+
3
+ services:
4
+ app:
5
+ build:
6
+ context: ..
7
+ dockerfile: .devcontainer/Dockerfile
8
+ args:
9
+ # Update 'VARIANT' to pick a version of Ruby: 3, 3.0, 2, 2.7, 2.6
10
+ # Append -bullseye or -buster to pin to an OS version.
11
+ # Use -bullseye variants on local arm64/Apple Silicon.
12
+ VARIANT: "3"
13
+
14
+ volumes:
15
+ - ..:/workspace:cached
16
+
17
+ # Overrides default command so things don't shut down after the process ends.
18
+ command: sleep infinity
19
+
20
+ # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
21
+ network_mode: service:db
22
+ # Uncomment the next line to use a non-root user for all processes.
23
+ # user: vscode
24
+
25
+ # Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
26
+ # (Adding the "ports" property to this file will not forward from a Codespace.)
27
+
28
+ db:
29
+ image: postgres:latest
30
+ restart: unless-stopped
31
+ volumes:
32
+ - postgres-data:/var/lib/postgresql/data
33
+ environment:
34
+ POSTGRES_USER: postgres
35
+ POSTGRES_DB: postgres
36
+ POSTGRES_PASSWORD: postgres
37
+ # Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally.
38
+ # (Adding the "ports" property to this file will not forward from a Codespace.)
39
+
40
+ volumes:
41
+ postgres-data: null
@@ -0,0 +1,32 @@
1
+ name: Check pull request
2
+
3
+ on:
4
+ - pull_request
5
+
6
+ jobs:
7
+ test:
8
+ runs-on: ubuntu-latest
9
+ services:
10
+ postgres:
11
+ image: postgres:14-alpine
12
+ env:
13
+ POSTGRES_USER: postgres
14
+ POSTGRES_PASSWORD: postgres
15
+ POSTGRES_DB: postgres
16
+ options: >-
17
+ --health-cmd pg_isready
18
+ --health-interval 10s
19
+ --health-timeout 5s
20
+ --health-retries 5
21
+ ports:
22
+ - 5432:5432
23
+ steps:
24
+ - uses: actions/checkout@v2
25
+ - uses: ruby/setup-ruby@v1
26
+ with:
27
+ ruby-version: 3.0
28
+ bundler-cache: true
29
+ - name: Install PostgreSQL client
30
+ run: sudo apt-get -yqq install libpq-dev
31
+ - name: Run tests
32
+ run: bundle exec rake
@@ -0,0 +1,26 @@
1
+ name: Release to RubyGems
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+
8
+ jobs:
9
+ release:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - uses: ruby/setup-ruby@v1
14
+ with:
15
+ ruby-version: 3.0 # Not needed with a .ruby-version file
16
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
17
+ - name: publish gem
18
+ run: |
19
+ mkdir -p $HOME/.gem
20
+ touch $HOME/.gem/credentials
21
+ chmod 0600 $HOME/.gem/credentials
22
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
23
+ gem build *.gemspec
24
+ gem push *.gem
25
+ env:
26
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_TOKEN}}"
data/.gitignore CHANGED
@@ -1,55 +1,148 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
1
+
2
+ # Created by https://www.toptal.com/developers/gitignore/api/ruby,visualstudiocode,windows,linux,macos
3
+ # Edit at https://www.toptal.com/developers/gitignore?templates=ruby,visualstudiocode,windows,linux,macos
4
+
5
+ ### Linux ###
6
+ *~
7
+
8
+ # temporary files which can be created if a process still has a handle open of a deleted file
9
+ .fuse_hidden*
10
+
11
+ # KDE directory preferences
12
+ .directory
13
+
14
+ # Linux trash folder which might appear on any partition or disk
15
+ .Trash-*
16
+
17
+ # .nfs files are created when an open file is removed but is still being accessed
18
+ .nfs*
19
+
20
+ ### macOS ###
21
+ # General
22
+ .DS_Store
23
+ .AppleDouble
24
+ .LSOverride
25
+
26
+ # Icon must end with two \r
27
+ Icon
28
+
29
+
30
+ # Thumbnails
31
+ ._*
32
+
33
+ # Files that might appear in the root of a volume
34
+ .DocumentRevisions-V100
35
+ .fseventsd
36
+ .Spotlight-V100
37
+ .TemporaryItems
38
+ .Trashes
39
+ .VolumeIcon.icns
40
+ .com.apple.timemachine.donotpresent
41
+
42
+ # Directories potentially created on remote AFP share
43
+ .AppleDB
44
+ .AppleDesktop
45
+ Network Trash Folder
46
+ Temporary Items
47
+ .apdisk
48
+
49
+ ### Ruby ###
50
+ *.gem
51
+ *.rbc
52
+ /.config
5
53
  /coverage/
6
- /doc/
54
+ /InstalledFiles
7
55
  /pkg/
8
56
  /spec/reports/
57
+ /spec/examples.txt
58
+ /test/tmp/
59
+ /test/version_tmp/
9
60
  /tmp/
10
61
 
11
- # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
12
- # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
62
+ # Used by dotenv library to load environment variables.
63
+ # .env
64
+
65
+ # Ignore Byebug command history file.
66
+ .byebug_history
67
+
68
+ ## Specific to RubyMotion:
69
+ .dat*
70
+ .repl_history
71
+ build/
72
+ *.bridgesupport
73
+ build-iPhoneOS/
74
+ build-iPhoneSimulator/
75
+
76
+ ## Specific to RubyMotion (use of CocoaPods):
77
+ #
78
+ # We recommend against adding the Pods directory to your .gitignore. However
79
+ # you should judge for yourself, the pros and cons are mentioned at:
80
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
81
+ # vendor/Pods/
82
+
83
+ ## Documentation cache and generated files:
84
+ /.yardoc/
85
+ /_yardoc/
86
+ /doc/
87
+ /rdoc/
88
+
89
+ ## Environment normalization:
90
+ /.bundle/
91
+ /vendor/bundle
92
+ /lib/bundler/man/
93
+
94
+ # for a library or gem, you might want to ignore these files since the code is
95
+ # intended to run in multiple environments; otherwise, check them in:
96
+ # Gemfile.lock
97
+ # .ruby-version
98
+ # .ruby-gemset
99
+
100
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
101
+ .rvmrc
102
+
103
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
104
+ # .rubocop-https?--*
13
105
 
14
- # User-specific stuff:
15
- .idea/workspace.xml
16
- .idea/tasks.xml
17
- .idea/dictionaries
18
- .idea/vcs.xml
19
- .idea/jsLibraryMappings.xml
20
- .idea/dataSources
106
+ ### VisualStudioCode ###
107
+ .vscode/*
108
+ !.vscode/settings.json
109
+ !.vscode/tasks.json
110
+ !.vscode/launch.json
111
+ !.vscode/extensions.json
112
+ *.code-workspace
21
113
 
22
- # Sensitive or high-churn files:
23
- .idea/dataSources.ids
24
- .idea/dataSources.xml
25
- .idea/dataSources.local.xml
26
- .idea/sqlDataSources.xml
27
- .idea/dynamic.xml
28
- .idea/uiDesigner.xml
114
+ # Local History for Visual Studio Code
115
+ .history/
29
116
 
30
- # Gradle:
31
- .idea/gradle.xml
32
- .idea/libraries
117
+ ### VisualStudioCode Patch ###
118
+ # Ignore all local history of files
119
+ .history
120
+ .ionide
33
121
 
34
- # Mongo Explorer plugin:
35
- .idea/mongoSettings.xml
122
+ ### Windows ###
123
+ # Windows thumbnail cache files
124
+ Thumbs.db
125
+ Thumbs.db:encryptable
126
+ ehthumbs.db
127
+ ehthumbs_vista.db
36
128
 
37
- ## File-based project format:
38
- *.iws
129
+ # Dump file
130
+ *.stackdump
39
131
 
40
- ## Plugin-specific files:
132
+ # Folder config file
133
+ [Dd]esktop.ini
41
134
 
42
- # IntelliJ
43
- /out/
135
+ # Recycle Bin used on file shares
136
+ $RECYCLE.BIN/
44
137
 
45
- # mpeltonen/sbt-idea plugin
46
- .idea_modules/
138
+ # Windows Installer files
139
+ *.cab
140
+ *.msi
141
+ *.msix
142
+ *.msm
143
+ *.msp
47
144
 
48
- # JIRA plugin
49
- atlassian-ide-plugin.xml
145
+ # Windows shortcuts
146
+ *.lnk
50
147
 
51
- # Crashlytics plugin (for Android Studio and IntelliJ)
52
- com_crashlytics_export_strings.xml
53
- crashlytics.properties
54
- crashlytics-build.properties
55
- fabric.properties
148
+ # End of https://www.toptal.com/developers/gitignore/api/ruby,visualstudiocode,windows,linux,macos
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ ## [0.3.0](https://www.github.com/openscript/awesome_hstore_translate/compare/v0.2.2...v0.3.0) (2021-10-25)
4
+
5
+
6
+ ### ⚠ BREAKING CHANGES
7
+
8
+ * Adds compatibility with Rails 6
9
+
10
+ ### Features
11
+
12
+ * Adds compatibility with Rails 6 ([3fdd9bc](https://www.github.com/openscript/awesome_hstore_translate/commit/3fdd9bc51e770fae74c867b6d28c182623394ab0))
13
+ * Updates ([5c7b7e7](https://www.github.com/openscript/awesome_hstore_translate/commit/5c7b7e7883bb87452ef60a8c629fb45146381a20))
data/Gemfile.lock ADDED
@@ -0,0 +1,60 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ awesome_hstore_translate (0.4.0)
5
+ activemodel (>= 5.0)
6
+ activerecord (>= 5.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (6.1.4.1)
12
+ activesupport (= 6.1.4.1)
13
+ activerecord (6.1.4.1)
14
+ activemodel (= 6.1.4.1)
15
+ activesupport (= 6.1.4.1)
16
+ activesupport (6.1.4.1)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 1.6, < 2)
19
+ minitest (>= 5.1)
20
+ tzinfo (~> 2.0)
21
+ zeitwerk (~> 2.3)
22
+ byebug (11.1.3)
23
+ concurrent-ruby (1.1.9)
24
+ database_cleaner (2.0.1)
25
+ database_cleaner-active_record (~> 2.0.0)
26
+ database_cleaner-active_record (2.0.1)
27
+ activerecord (>= 5.a)
28
+ database_cleaner-core (~> 2.0.0)
29
+ database_cleaner-core (2.0.1)
30
+ docile (1.4.0)
31
+ i18n (1.8.10)
32
+ concurrent-ruby (~> 1.0)
33
+ minitest (5.14.4)
34
+ pg (1.2.3)
35
+ rake (13.0.6)
36
+ simplecov (0.21.2)
37
+ docile (~> 1.1)
38
+ simplecov-html (~> 0.11)
39
+ simplecov_json_formatter (~> 0.1)
40
+ simplecov-html (0.12.3)
41
+ simplecov_json_formatter (0.1.3)
42
+ tzinfo (2.0.4)
43
+ concurrent-ruby (~> 1.0)
44
+ zeitwerk (2.5.1)
45
+
46
+ PLATFORMS
47
+ x86_64-linux
48
+
49
+ DEPENDENCIES
50
+ awesome_hstore_translate!
51
+ bundler (~> 2.2)
52
+ byebug (~> 11.1)
53
+ database_cleaner (~> 2.0)
54
+ minitest (~> 5.0)
55
+ pg (~> 1.2)
56
+ rake (~> 13.0)
57
+ simplecov (~> 0.21)
58
+
59
+ BUNDLED WITH
60
+ 2.2.22
data/README.md CHANGED
@@ -1,30 +1,34 @@
1
1
  # Awesome Hstore Translate
2
+
2
3
  [![Gem Version](https://badge.fury.io/rb/awesome_hstore_translate.svg)](https://badge.fury.io/rb/awesome_hstore_translate)
3
4
 
4
5
  This gem uses PostgreSQLs hstore datatype and ActiveRecord models to translate model data. It is based on the gem
5
- [`hstore_translate`](https://github.com/Leadformance/hstore_translate) by Rob Worely.
6
+ [`hstore_translate`](https://github.com/Leadformance/hstore_translate) by Rob Worely. An alternative is [`json_translate`](https://github.com/cfabianski/json_translate).
6
7
 
7
- - It's ready for Rails 5
8
- - No extra columns or tables needed to operate
9
- - Clean naming in the database model
10
- - Everything is well tested
8
+ - Works with Rails 5 and 6
9
+ - No extra columns or tables needed to operate
10
+ - Clean naming in the database model
11
+ - Everything is well tested
11
12
 
12
13
  ## Features
13
- - [x] `v0.1.0` Attributes override / Raw attributes
14
- - [x] `v0.1.0` Fallbacks
15
- - [x] `v0.1.0` Language specific accessors
16
- - [x] `v0.2.0` Awesome Hstore Translate as drop in replace for [`hstore_translate`](https://github.com/Leadformance/hstore_translate)
17
- - `with_[attr]_translation(str)` is not supported
18
- - [x] `v0.2.2` Support record selection via ActiveRecord (e. g. `where`, `find_by`, ..)
19
- - [x] `v0.3.0` Support record ordering via ActiveRecord `order`
20
- - [ ] `backlog` Support `friendly_id` (see `friendly_id-awesome_hstore` gem)
14
+
15
+ - [x] `v0.1.0` Attributes override / Raw attributes
16
+ - [x] `v0.1.0` Fallbacks
17
+ - [x] `v0.1.0` Language specific accessors
18
+ - [x] `v0.2.0` Awesome Hstore Translate as drop in replace for [`hstore_translate`](https://github.com/Leadformance/hstore_translate)
19
+ - `with_[attr]_translation(str)` is not supported
20
+ - [x] `v0.2.2` Support record selection via ActiveRecord (e. g. `where`, `find_by`, ..)
21
+ - [x] `v0.3.0` Support record ordering via ActiveRecord `order`
22
+ - [ ] `backlog` Support `friendly_id` (see `friendly_id-awesome_hstore` gem)
21
23
 
22
24
  ## Requirements
23
- - ActiveRecord `>= 5`
24
- - Please use [`hstore_translate`](https://github.com/Leadformance/hstore_translate), if you are on an older version.
25
- - I18n
25
+
26
+ - ActiveRecord `>= 5`
27
+ - Please use [`hstore_translate`](https://github.com/Leadformance/hstore_translate), if you are on an older version.
28
+ - I18n
26
29
 
27
30
  ## Installation
31
+
28
32
  Add this line to your application's Gemfile:
29
33
 
30
34
  ```ruby
@@ -40,19 +44,23 @@ Or install it yourself as:
40
44
  $ gem install awesome_hstore_translate
41
45
 
42
46
  ## Usage
47
+
43
48
  Use `translates` in your models, to define the attributes, which should be translateable:
49
+
44
50
  ```ruby
45
51
  class Page < ActiveRecord::Base
46
52
  translates :title, :content
47
53
  end
48
54
  ```
55
+
49
56
  Make sure that the datatype of this columns is `hstore`:
57
+
50
58
  ```ruby
51
59
  class CreatePages < ActiveRecord::Migration
52
60
  def change
53
61
  # Make sure you enable the hstore extenion
54
62
  enable_extension 'hstore' unless extension_enabled?('hstore')
55
-
63
+
56
64
  create_table :pages do |t|
57
65
  t.column :title, :hstore
58
66
  t.column :content, :hstore
@@ -63,6 +71,7 @@ end
63
71
  ```
64
72
 
65
73
  Use the model attributes per locale:
74
+
66
75
  ```ruby
67
76
  p = Page.first
68
77
 
@@ -78,15 +87,23 @@ end
78
87
  ```
79
88
 
80
89
  The raw data is available via the suffix `_raw`:
90
+
81
91
  ```ruby
82
92
  p = Page.new(:title_raw => {'en' => 'English title', 'de' => 'Deutscher Titel'})
83
93
 
84
94
  p.title_raw # => {'en' => 'English title', 'de' => 'Deutscher Titel'}
85
95
  ```
86
96
 
97
+ Translated attributes:
98
+
99
+ ```ruby
100
+ Page.translated_attribute_names # [:title]
101
+ ```
87
102
 
88
103
  ### Fallbacks
104
+
89
105
  It's possible to fall back to another language, if there is no or an empty value for the primary language. To enable fallbacks you can set `I18n.fallbacks` to `true` or enable it manually in the model:
106
+
90
107
  ```ruby
91
108
  class Page < ActiveRecord::Base
92
109
  translates :title, :content, fallbacks: true
@@ -94,6 +111,7 @@ end
94
111
  ```
95
112
 
96
113
  Set `I18n.default_locale` or `I18n.fallbacks` to define the fallback:
114
+
97
115
  ```ruby
98
116
  I18n.fallbacks.map(:en => :de) # => if :en is nil or empty, it will use :de
99
117
 
@@ -105,6 +123,7 @@ end
105
123
  ```
106
124
 
107
125
  It's possible to activate (`with_fallbacks`) or deactivate (`without_fallbacks`) fallbacks for a block execution:
126
+
108
127
  ```ruby
109
128
  p = PageWithoutFallbacks.new(:title_raw => {'de' => 'Deutscher Titel'})
110
129
 
@@ -116,7 +135,9 @@ end
116
135
  ```
117
136
 
118
137
  ### Accessors
138
+
119
139
  Convenience accessors can be enabled via the model descriptor:
140
+
120
141
  ```ruby
121
142
  class Page < ActiveRecord::Base
122
143
  translates :title, :content, accessors: [:de, :en]
@@ -124,6 +145,7 @@ end
124
145
  ```
125
146
 
126
147
  It's also make sense to activate the accessors for all available locales:
148
+
127
149
  ```ruby
128
150
  class Page < ActiveRecord::Base
129
151
  translates :title, :content, accessors: I18n.available_locales
@@ -131,6 +153,7 @@ end
131
153
  ```
132
154
 
133
155
  Now locale-suffixed accessors can be used:
156
+
134
157
  ```ruby
135
158
  p = Page.create!(:title_en => 'English title', :title_de => 'Deutscher Titel')
136
159
 
@@ -138,8 +161,16 @@ p.title_en # => English title
138
161
  p.title_de # => Deutscher Titel
139
162
  ```
140
163
 
164
+ Translated accessor attributes:
165
+
166
+ ```ruby
167
+ Page.translated_accessor_names # [:title_en, :title_de]
168
+ ```
169
+
141
170
  ### Find
171
+
142
172
  `awesome_hstore_translate` patches ActiveRecord, so you can conviniently use `where` and `find_by` as you like.
173
+
143
174
  ```ruby
144
175
  Page.create!(:title_en => 'English title', :title_de => 'Deutscher Titel')
145
176
  Page.create!(:title_en => 'Another English title', :title_de => 'Noch ein Deutscher Titel')
@@ -148,6 +179,7 @@ Page.where(title: 'Another English title') # => Page with title 'Another Englis
148
179
  ```
149
180
 
150
181
  ### Order
182
+
151
183
  `awesome_hstore_translate` patches ActiveRecord, so you can conviniently use `order` as you like.
152
184
 
153
185
  ```ruby
@@ -158,35 +190,38 @@ Page.all.order(title: :desc) # => Page with title 'English title'
158
190
  ```
159
191
 
160
192
  ### Limitations
193
+
161
194
  `awesome_hstore_translate` patches ActiveRecord, which create the limitation, that a with `where` chained `first_or_create` and `first_or_create!` **doesn't work** as expected.
162
195
  Here is an example, which **won't** work:
163
196
 
164
- ``` ruby
197
+ ```ruby
165
198
  Page.where(title: 'Titre français').first_or_create!
166
199
  ```
167
200
 
168
201
  A workaround is:
169
202
 
170
- ``` ruby
203
+ ```ruby
171
204
  Page.where(title: 'Titre français').first_or_create!(title: 'Titre français')
172
205
  ```
173
206
 
174
207
  The where clause is internally rewritten to `WHERE 'Titre français' = any(avals(title))`, so the `title: 'Titre français'` is not bound to the scope.
175
208
 
176
209
  ### Upgrade from [`hstore_translate`](https://github.com/Leadformance/hstore_translate)
210
+
177
211
  1. Replace the [`hstore_translate`](https://github.com/Leadformance/hstore_translate) with `awesome_hstore_translate` in your Gemfile
178
212
  1. Activate accessors, if you used the [`hstore_translate`](https://github.com/Leadformance/hstore_translate) accessors
179
213
  1. Replace `with_[attr]_translation(str)` with equivalents (see "Support record selection via ActiveRecord" feature)
180
214
 
181
215
  ## Development
216
+
182
217
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
183
218
 
184
219
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
185
220
 
186
221
  ## Contributing
187
- Bug reports and pull requests are welcome on [GitHub](https://github.com/openscript/awesome_hstore_translate). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
188
222
 
223
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/openscript/awesome_hstore_translate). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
189
224
 
190
225
  ## License
191
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
192
226
 
227
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -6,8 +6,8 @@ require 'awesome_hstore_translate/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'awesome_hstore_translate'
8
8
  spec.version = AwesomeHstoreTranslate::VERSION
9
- spec.authors = ['Robin Bühler', 'Rob Worley']
10
- spec.email = ['public+rubygems@openscript.ch']
9
+ spec.authors = ['Robin Bühler', 'Rob Worley', 'Edouard Piron']
10
+ spec.email = ['r+rubygems@obin.ch']
11
11
 
12
12
  spec.summary = 'Using PostgreSQLs hstore datatype to provide ActiveRecord models data translation.'
13
13
  spec.description = 'This gem uses PostgreSQLs hstore datatype and ActiveRecord models to translate model data. It is based on the gem hstore_translate by Rob Worely.'
@@ -19,13 +19,14 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ['lib']
21
21
 
22
- spec.add_dependency 'activerecord', '>= 5.0', '< 6'
23
- spec.add_dependency 'activemodel', '>= 5.0', '< 6'
22
+ spec.add_dependency 'activerecord', '>= 5.0'
23
+ spec.add_dependency 'activemodel', '>= 5.0'
24
24
 
25
- spec.add_development_dependency 'bundler', '~> 1.12'
26
- spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'byebug', '~> 11.1'
26
+ spec.add_development_dependency 'bundler', '~> 2.2'
27
+ spec.add_development_dependency 'rake', '~> 13.0'
27
28
  spec.add_development_dependency 'minitest', '~> 5.0'
28
- spec.add_development_dependency 'database_cleaner', '~> 1.5'
29
- spec.add_development_dependency 'pg', '~> 0.18'
30
- spec.add_development_dependency 'simplecov', '~> 0.12'
29
+ spec.add_development_dependency 'database_cleaner', '~> 2.0'
30
+ spec.add_development_dependency 'pg', '~> 1.2'
31
+ spec.add_development_dependency 'simplecov', '~> 0.21'
31
32
  end
@@ -7,6 +7,7 @@ module AwesomeHstoreTranslate
7
7
  translation_options[:accessors].each do |locale|
8
8
  define_reader_accessor(attr, locale)
9
9
  define_writer_accessor(attr, locale)
10
+ self.translated_accessor_names << :"#{attr}_#{locale}"
10
11
  end
11
12
  end
12
13
 
@@ -27,4 +28,4 @@ module AwesomeHstoreTranslate
27
28
  end
28
29
  end
29
30
  end
30
- end
31
+ end
@@ -40,6 +40,9 @@ module AwesomeHstoreTranslate
40
40
  def expose_translated_attrs(attr_names)
41
41
  class_attribute :translated_attribute_names
42
42
  self.translated_attribute_names = attr_names
43
+
44
+ class_attribute :translated_accessor_names
45
+ self.translated_accessor_names = []
43
46
  end
44
47
 
45
48
  def bootstrap(options, attr_names)
@@ -52,4 +55,4 @@ module AwesomeHstoreTranslate
52
55
  end
53
56
  end
54
57
  end
55
- end
58
+ end
@@ -46,7 +46,7 @@ module AwesomeHstoreTranslate
46
46
  end
47
47
 
48
48
  translated_attrs.each do |key, value|
49
- query.order!("#{key} -> '#{I18n.locale.to_s}' #{value}")
49
+ query.order!(Arel.sql("#{key} -> '#{I18n.locale.to_s}' #{value}"))
50
50
  end
51
51
 
52
52
  query
@@ -62,8 +62,16 @@ module AwesomeHstoreTranslate
62
62
  end
63
63
 
64
64
  def untranslated_attributes(opts)
65
+ return safe_untranslated_attributes(opts) if opts.is_a?(Array)
66
+
65
67
  opts.reject{ |key, _| self.translated_attribute_names.include?(key) }
66
68
  end
69
+
70
+ def safe_untranslated_attributes(opts)
71
+ opts
72
+ .reject { |opt| opt.is_a?(Arel::Nodes::Ordering) }
73
+ .map! { |opt| Arel.sql(opt.to_s) }
74
+ end
67
75
  end
68
76
  end
69
77
  end
@@ -1,3 +1,3 @@
1
1
  module AwesomeHstoreTranslate
2
- VERSION = '0.3.1'
2
+ VERSION = '0.4.0'
3
3
  end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awesome_hstore_translate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robin Bühler
8
8
  - Rob Worley
9
+ - Edouard Piron
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2017-02-03 00:00:00.000000000 Z
13
+ date: 2021-10-25 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: activerecord
@@ -18,9 +19,6 @@ dependencies:
18
19
  - - ">="
19
20
  - !ruby/object:Gem::Version
20
21
  version: '5.0'
21
- - - "<"
22
- - !ruby/object:Gem::Version
23
- version: '6'
24
22
  type: :runtime
25
23
  prerelease: false
26
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -28,9 +26,6 @@ dependencies:
28
26
  - - ">="
29
27
  - !ruby/object:Gem::Version
30
28
  version: '5.0'
31
- - - "<"
32
- - !ruby/object:Gem::Version
33
- version: '6'
34
29
  - !ruby/object:Gem::Dependency
35
30
  name: activemodel
36
31
  requirement: !ruby/object:Gem::Requirement
@@ -38,9 +33,6 @@ dependencies:
38
33
  - - ">="
39
34
  - !ruby/object:Gem::Version
40
35
  version: '5.0'
41
- - - "<"
42
- - !ruby/object:Gem::Version
43
- version: '6'
44
36
  type: :runtime
45
37
  prerelease: false
46
38
  version_requirements: !ruby/object:Gem::Requirement
@@ -48,37 +40,48 @@ dependencies:
48
40
  - - ">="
49
41
  - !ruby/object:Gem::Version
50
42
  version: '5.0'
51
- - - "<"
43
+ - !ruby/object:Gem::Dependency
44
+ name: byebug
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '11.1'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
52
55
  - !ruby/object:Gem::Version
53
- version: '6'
56
+ version: '11.1'
54
57
  - !ruby/object:Gem::Dependency
55
58
  name: bundler
56
59
  requirement: !ruby/object:Gem::Requirement
57
60
  requirements:
58
61
  - - "~>"
59
62
  - !ruby/object:Gem::Version
60
- version: '1.12'
63
+ version: '2.2'
61
64
  type: :development
62
65
  prerelease: false
63
66
  version_requirements: !ruby/object:Gem::Requirement
64
67
  requirements:
65
68
  - - "~>"
66
69
  - !ruby/object:Gem::Version
67
- version: '1.12'
70
+ version: '2.2'
68
71
  - !ruby/object:Gem::Dependency
69
72
  name: rake
70
73
  requirement: !ruby/object:Gem::Requirement
71
74
  requirements:
72
75
  - - "~>"
73
76
  - !ruby/object:Gem::Version
74
- version: '10.0'
77
+ version: '13.0'
75
78
  type: :development
76
79
  prerelease: false
77
80
  version_requirements: !ruby/object:Gem::Requirement
78
81
  requirements:
79
82
  - - "~>"
80
83
  - !ruby/object:Gem::Version
81
- version: '10.0'
84
+ version: '13.0'
82
85
  - !ruby/object:Gem::Dependency
83
86
  name: minitest
84
87
  requirement: !ruby/object:Gem::Requirement
@@ -99,56 +102,62 @@ dependencies:
99
102
  requirements:
100
103
  - - "~>"
101
104
  - !ruby/object:Gem::Version
102
- version: '1.5'
105
+ version: '2.0'
103
106
  type: :development
104
107
  prerelease: false
105
108
  version_requirements: !ruby/object:Gem::Requirement
106
109
  requirements:
107
110
  - - "~>"
108
111
  - !ruby/object:Gem::Version
109
- version: '1.5'
112
+ version: '2.0'
110
113
  - !ruby/object:Gem::Dependency
111
114
  name: pg
112
115
  requirement: !ruby/object:Gem::Requirement
113
116
  requirements:
114
117
  - - "~>"
115
118
  - !ruby/object:Gem::Version
116
- version: '0.18'
119
+ version: '1.2'
117
120
  type: :development
118
121
  prerelease: false
119
122
  version_requirements: !ruby/object:Gem::Requirement
120
123
  requirements:
121
124
  - - "~>"
122
125
  - !ruby/object:Gem::Version
123
- version: '0.18'
126
+ version: '1.2'
124
127
  - !ruby/object:Gem::Dependency
125
128
  name: simplecov
126
129
  requirement: !ruby/object:Gem::Requirement
127
130
  requirements:
128
131
  - - "~>"
129
132
  - !ruby/object:Gem::Version
130
- version: '0.12'
133
+ version: '0.21'
131
134
  type: :development
132
135
  prerelease: false
133
136
  version_requirements: !ruby/object:Gem::Requirement
134
137
  requirements:
135
138
  - - "~>"
136
139
  - !ruby/object:Gem::Version
137
- version: '0.12'
140
+ version: '0.21'
138
141
  description: This gem uses PostgreSQLs hstore datatype and ActiveRecord models to
139
142
  translate model data. It is based on the gem hstore_translate by Rob Worely.
140
143
  email:
141
- - public+rubygems@openscript.ch
144
+ - r+rubygems@obin.ch
142
145
  executables:
143
146
  - console
144
147
  - setup
145
148
  extensions: []
146
149
  extra_rdoc_files: []
147
150
  files:
151
+ - ".devcontainer/Dockerfile"
152
+ - ".devcontainer/devcontainer.json"
153
+ - ".devcontainer/docker-compose.yml"
154
+ - ".github/workflows/pull.yml"
155
+ - ".github/workflows/release.yml"
148
156
  - ".gitignore"
149
- - ".travis.yml"
157
+ - CHANGELOG.md
150
158
  - CODE_OF_CONDUCT.md
151
159
  - Gemfile
160
+ - Gemfile.lock
152
161
  - LICENSE.txt
153
162
  - README.md
154
163
  - Rakefile
@@ -184,8 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
193
  - !ruby/object:Gem::Version
185
194
  version: '0'
186
195
  requirements: []
187
- rubyforge_project:
188
- rubygems_version: 2.5.1
196
+ rubygems_version: 3.2.22
189
197
  signing_key:
190
198
  specification_version: 4
191
199
  summary: Using PostgreSQLs hstore datatype to provide ActiveRecord models data translation.
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.3.1
5
- before_install: gem install bundler -v 1.12.5