translatable_fields 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1205f77c761a53f2055c75ac6f2cb9616cd4d0aa4387f68e150c8dc3133001f3
4
+ data.tar.gz: b627a2725aaf1f4cd52fa1c9ee1dec06adf35bb718d53c3e6f59d10d4346c844
5
+ SHA512:
6
+ metadata.gz: c33ace1c25c702b42fd553fe183308ee51045d18e426e4a20be593f7ba97caa74d0e655af0ecf894c387ff6ba433f02e747a11c56433b0753cdfc0e7bd5278ab
7
+ data.tar.gz: 6e99efa38ce4752517e60218db2ca7d3682291641fb6c7bdbfe108dd4dd43be391d09673f5546ed16312d8a45d039c1143ca3ff1940d57cd58e3a944a95a34ff
@@ -0,0 +1,25 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ docker:
5
+ - image: circleci/ruby:2.6.3-node-browsers
6
+
7
+ steps:
8
+ - checkout
9
+ - restore_cache:
10
+ keys:
11
+ - translatable_fields-{{ checksum "Gemfile.lock" }}
12
+ - translatable_fields-
13
+
14
+ - run:
15
+ name: install dependencies
16
+ command: bundle check || bundle install
17
+
18
+ - save_cache:
19
+ paths:
20
+ - ./vendor/bundle
21
+ key: translatable_fields-{{ checksum "Gemfile.lock" }}
22
+
23
+ - run:
24
+ name: run tests
25
+ command: bundle exec rspec
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,55 @@
1
+ ---
2
+ AllCops:
3
+ DisplayCopNames: true
4
+ TargetRubyVersion: 2.6
5
+
6
+ Metrics/LineLength:
7
+ Max: 120
8
+
9
+ Style/Documentation:
10
+ Enabled: false
11
+
12
+ Metrics/MethodLength:
13
+ Enabled: false
14
+
15
+ Lint/AmbiguousBlockAssociation:
16
+ Enabled: false
17
+
18
+ Naming/UncommunicativeMethodParamName:
19
+ MinNameLength: 2
20
+
21
+ Metrics/BlockLength:
22
+ Enabled: false
23
+
24
+ Style/Alias:
25
+ Enabled: false
26
+
27
+ Style/ClassAndModuleChildren:
28
+ Enabled: false
29
+
30
+ Style/DateTime:
31
+ Enabled: false
32
+
33
+ Style/FrozenStringLiteralComment:
34
+ Enabled: false
35
+
36
+ Style/ModuleFunction:
37
+ Enabled: false
38
+
39
+ Style/RaiseArgs:
40
+ Enabled: false
41
+
42
+ Style/RescueModifier:
43
+ Exclude:
44
+ - '**/*_spec.rb'
45
+
46
+ Style/Semicolon:
47
+ Exclude:
48
+ - '**/*_spec.rb'
49
+
50
+ Style/StringLiterals:
51
+ EnforcedStyle: double_quotes
52
+
53
+ Style/SingleLineMethods:
54
+ Exclude:
55
+ - '**/*_spec.rb'
@@ -0,0 +1 @@
1
+ 2.6.3
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in translatable_fields.gemspec
6
+ gemspec
@@ -0,0 +1,78 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ translatable_fields (0.1.0)
5
+ activesupport (>= 4.0.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (6.0.0)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 0.7, < 2)
13
+ minitest (~> 5.1)
14
+ tzinfo (~> 1.1)
15
+ zeitwerk (~> 2.1, >= 2.1.8)
16
+ ast (2.4.0)
17
+ coderay (1.1.2)
18
+ concurrent-ruby (1.1.5)
19
+ diff-lcs (1.3)
20
+ docile (1.3.2)
21
+ i18n (1.7.0)
22
+ concurrent-ruby (~> 1.0)
23
+ jaro_winkler (1.5.4)
24
+ json (2.2.0)
25
+ method_source (0.9.2)
26
+ minitest (5.13.0)
27
+ parallel (1.18.0)
28
+ parser (2.6.5.0)
29
+ ast (~> 2.4.0)
30
+ pry (0.12.2)
31
+ coderay (~> 1.1.0)
32
+ method_source (~> 0.9.0)
33
+ rainbow (3.0.0)
34
+ rspec (3.9.0)
35
+ rspec-core (~> 3.9.0)
36
+ rspec-expectations (~> 3.9.0)
37
+ rspec-mocks (~> 3.9.0)
38
+ rspec-core (3.9.0)
39
+ rspec-support (~> 3.9.0)
40
+ rspec-expectations (3.9.0)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.9.0)
43
+ rspec-mocks (3.9.0)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.9.0)
46
+ rspec-support (3.9.0)
47
+ rubocop (0.76.0)
48
+ jaro_winkler (~> 1.5.1)
49
+ parallel (~> 1.10)
50
+ parser (>= 2.6)
51
+ rainbow (>= 2.2.2, < 4.0)
52
+ ruby-progressbar (~> 1.7)
53
+ unicode-display_width (>= 1.4.0, < 1.7)
54
+ ruby-progressbar (1.10.1)
55
+ simplecov (0.17.1)
56
+ docile (~> 1.1)
57
+ json (>= 1.8, < 3)
58
+ simplecov-html (~> 0.10.0)
59
+ simplecov-html (0.10.2)
60
+ thread_safe (0.3.6)
61
+ tzinfo (1.2.5)
62
+ thread_safe (~> 0.1)
63
+ unicode-display_width (1.6.0)
64
+ zeitwerk (2.2.0)
65
+
66
+ PLATFORMS
67
+ ruby
68
+
69
+ DEPENDENCIES
70
+ bundler (~> 1.17)
71
+ pry
72
+ rspec (~> 3.0)
73
+ rubocop
74
+ simplecov
75
+ translatable_fields!
76
+
77
+ BUNDLED WITH
78
+ 1.17.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Ruslan Tolstov
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.
@@ -0,0 +1,70 @@
1
+ # TranslatableFields
2
+
3
+ Translate your fields in ActiveRecord.
4
+
5
+ Rails concern allow you to translate your models' attribute values with prefixes like `en_title` or `title_en`
6
+
7
+ ## Requirements
8
+
9
+ * ActiveRecord
10
+ * I18n
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'translatable_fields'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install translatable_fields
27
+ $ rails g translatable_fields:install
28
+
29
+ ## Set up
30
+ ```diff
31
+ # config/initializers/translatable_fields.rb
32
+ TranslatableFields.configure do |config|
33
+ # Set up your mode:
34
+ # :prefix_at_the_beginning (default) - for fields like en_title, ar_title
35
+ # :prefix_in_the_end - for fields like title_en, title_ar
36
+ #
37
+ + config.mode = :prefix_at_the_beginning
38
+ end
39
+ ```
40
+
41
+ ## Usage example
42
+ ```diff
43
+ class Allergy < ApplicationRecord
44
+ + include TranslatableFields::Concern
45
+
46
+ + translatable_fields(:title, :description)
47
+ end
48
+ ```
49
+
50
+ ```ruby
51
+ Allergy.first.title
52
+ => "Food Allergy"
53
+ Allergy.first.description
54
+ => "There are different types of allergic reactions to foods"
55
+ ```
56
+
57
+ ## Thanks
58
+ Implemented based on ideas [@GalenkoEugene](https://github.com/GalenkoEugene), [@AlexTua](https://github.com/AlexTua) thanks, guys.
59
+
60
+ ## Contributing
61
+
62
+ 1. Fork it ( link )
63
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
64
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
65
+ 4. Push to the branch (`git push origin my-new-feature`)
66
+ 5. Create a new Pull Request
67
+
68
+ ## License
69
+
70
+ The MIT License
@@ -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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ar/perekladach"
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(__FILE__)
@@ -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/generators"
2
+
3
+ module TranslatableFields
4
+ class InstallGenerator < Rails::Generators::Base
5
+ source_root File.expand_path("templates", __dir__)
6
+
7
+ def add_initializer
8
+ template("translatable_fields.rb", "config/initializers/translatable_fields.rb")
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ TranslatableFields.configure do |config|
2
+ # Set up your mode:
3
+ # :prefix_at_the_beginning (default) - for fields like en_title, ar_title
4
+ # :prefix_in_the_end - for fields like title_en, title_ar
5
+ #
6
+ # config.mode = :prefix_at_the_beginning
7
+ end
@@ -0,0 +1,13 @@
1
+ require "translatable_fields/version"
2
+ require "translatable_fields/configuration"
3
+ require "translatable_fields/concern"
4
+
5
+ module TranslatableFields
6
+ def self.configure
7
+ yield(config)
8
+ end
9
+
10
+ def self.config
11
+ @config ||= Configuration.new
12
+ end
13
+ end
@@ -0,0 +1,27 @@
1
+ require "active_support/concern"
2
+
3
+ module TranslatableFields
4
+ module Concern
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ def field_prefix(field)
9
+ if TranslatableFields.config.mode&.to_sym == :prefix_at_the_beginning
10
+ "#{I18n.locale}_#{field}"
11
+ else
12
+ "#{field}_#{I18n.locale}"
13
+ end
14
+ end
15
+ end
16
+
17
+ class_methods do
18
+ def translatable_fields(*fields)
19
+ fields.each do |field|
20
+ define_method(field) do
21
+ public_send(field_prefix(field))
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,9 @@
1
+ module TranslatableFields
2
+ class Configuration
3
+ attr_accessor :mode
4
+
5
+ def initialize
6
+ @mode = :prefix_at_the_beginning
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module TranslatableFields
2
+ VERSION = "0.1.0".freeze
3
+ end
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "translatable_fields/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "translatable_fields"
7
+ spec.version = TranslatableFields::VERSION
8
+ spec.authors = ["Yevhenii Halenko", "Oleksii Tokarchuk", "Ruslan Tolstov"]
9
+ spec.email = ["ruslan.tolstov.ua@gmail.com"]
10
+
11
+ spec.summary = "Translate your fields in ActiveRecord. Rails library allow you to translate your models' attribute values with prefixes like `en_title` or `title_en`"
12
+ spec.description = "Translate your fields in ActiveRecord."
13
+ spec.homepage = "https://github.com/ruslantolstov/translatable_fields"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec|features)/}) }
18
+ end
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "activesupport", ">= 4.0.0"
23
+ spec.add_development_dependency "bundler", "~> 1.17"
24
+ spec.add_development_dependency "pry"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "rubocop"
27
+ spec.add_development_dependency "simplecov"
28
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: translatable_fields
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yevhenii Halenko
8
+ - Oleksii Tokarchuk
9
+ - Ruslan Tolstov
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2019-10-31 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: 4.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: 4.0.0
29
+ - !ruby/object:Gem::Dependency
30
+ name: bundler
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '1.17'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.17'
43
+ - !ruby/object:Gem::Dependency
44
+ name: pry
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: rspec
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '3.0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '3.0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: rubocop
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ - !ruby/object:Gem::Dependency
86
+ name: simplecov
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ description: Translate your fields in ActiveRecord.
100
+ email:
101
+ - ruslan.tolstov.ua@gmail.com
102
+ executables:
103
+ - console
104
+ - setup
105
+ extensions: []
106
+ extra_rdoc_files: []
107
+ files:
108
+ - ".circleci/config.yml"
109
+ - ".gitignore"
110
+ - ".rspec"
111
+ - ".rubocop.yml"
112
+ - ".ruby-version"
113
+ - Gemfile
114
+ - Gemfile.lock
115
+ - LICENSE.txt
116
+ - README.md
117
+ - Rakefile
118
+ - bin/console
119
+ - bin/setup
120
+ - lib/generators/translatable_fields/install/install_generator.rb
121
+ - lib/generators/translatable_fields/install/templates/translatable_fields.rb
122
+ - lib/translatable_fields.rb
123
+ - lib/translatable_fields/concern.rb
124
+ - lib/translatable_fields/configuration.rb
125
+ - lib/translatable_fields/version.rb
126
+ - translatable_fields.gemspec
127
+ homepage: https://github.com/ruslantolstov/translatable_fields
128
+ licenses:
129
+ - MIT
130
+ metadata: {}
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubygems_version: 3.0.3
147
+ signing_key:
148
+ specification_version: 4
149
+ summary: Translate your fields in ActiveRecord. Rails library allow you to translate
150
+ your models' attribute values with prefixes like `en_title` or `title_en`
151
+ test_files: []