variantable 0.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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +1 -0
- data/lib/variantable.rb +5 -0
- data/lib/variantable/translates/instance_methods.rb +77 -0
- data/lib/variantable/variantable.rb +26 -0
- data/lib/variantable/version.rb +3 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 59bccdfcb1f54dc5b85219f4f134fe5a948346f875503a991226c916eae27afd
|
4
|
+
data.tar.gz: 812d0817a0ae68fa8aaa5b18d5d92abce02f0a853ca0f3454aa57e96cfd6588b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9af527513128a2d2e5465eba88c94c7db15c82d5fdd35278f510955de767723d21e29dafba48322e3574070800bc20081329b33f95e97fde68f2fb9473fa839a
|
7
|
+
data.tar.gz: bc10fd7c26442259e977ab4a1cc8c0770ebf52ffb408bb60006087338776afb40c97ed6b00e36417a8c114ff0f1d64f477cc89cb30e8c8a72d85fc08fa073166
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Rob Worley
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Variantable gem made from the base of JSONTranslate gem.
|
data/lib/variantable.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
module JSONTranslate
|
2
|
+
module Translates
|
3
|
+
module InstanceMethods
|
4
|
+
def disable_fallback
|
5
|
+
toggle_fallback(false)
|
6
|
+
yield if block_given?
|
7
|
+
end
|
8
|
+
|
9
|
+
def enable_fallback
|
10
|
+
toggle_fallback(true)
|
11
|
+
yield if block_given?
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
attr_reader :enabled_fallback
|
17
|
+
|
18
|
+
def json_translate_fallback_locales(locale)
|
19
|
+
if enabled_fallback != false && I18n.respond_to?(:fallbacks)
|
20
|
+
Array(I18n.fallbacks[locale])
|
21
|
+
else
|
22
|
+
Array(locale)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def read_json_translation(attr_name, locale = I18n.locale, fallback = true, **params)
|
27
|
+
translations = public_send("#{attr_name}#{SUFFIX}") || {}
|
28
|
+
|
29
|
+
selected_locale = locale
|
30
|
+
if fallback
|
31
|
+
selected_locale = json_translate_fallback_locales(locale).detect do |available_locale|
|
32
|
+
translations[available_locale.to_s].present?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
translation = translations[selected_locale.to_s]
|
37
|
+
|
38
|
+
if translation && params.present?
|
39
|
+
begin
|
40
|
+
translation = I18n.interpolate(translation, params)
|
41
|
+
rescue I18n::MissingInterpolationArgument
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
translation
|
46
|
+
end
|
47
|
+
|
48
|
+
def write_json_translation(attr_name, value, locale = I18n.locale)
|
49
|
+
value = value.presence
|
50
|
+
translation_store = "#{attr_name}#{SUFFIX}"
|
51
|
+
translations = public_send(translation_store) || {}
|
52
|
+
public_send("#{translation_store}_will_change!") unless translations[locale.to_s] == value
|
53
|
+
if value
|
54
|
+
translations[locale.to_s] = value
|
55
|
+
else
|
56
|
+
translations.delete(locale.to_s)
|
57
|
+
end
|
58
|
+
public_send("#{translation_store}=", translations)
|
59
|
+
value
|
60
|
+
end
|
61
|
+
|
62
|
+
def toggle_fallback(enabled)
|
63
|
+
if block_given?
|
64
|
+
old_value = @enabled_fallback
|
65
|
+
begin
|
66
|
+
@enabled_fallback = enabled
|
67
|
+
yield
|
68
|
+
ensure
|
69
|
+
@enabled_fallback = old_value
|
70
|
+
end
|
71
|
+
else
|
72
|
+
@enabled_fallback = enabled
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Variantable
|
2
|
+
module Variantable
|
3
|
+
SUFFIX = "_variantes".freeze
|
4
|
+
VARIANT_TABLE = "platform_editorial_variants"
|
5
|
+
|
6
|
+
def variante_fields(*attrs)
|
7
|
+
include InstanceMethods
|
8
|
+
|
9
|
+
class_attribute :variante_attribute_names
|
10
|
+
|
11
|
+
attrs.each do |attr_name|
|
12
|
+
define_method attr_name do |**params|
|
13
|
+
read_variante(attr_name, params)
|
14
|
+
end
|
15
|
+
|
16
|
+
define_method "#{attr_name}=" do |**params|
|
17
|
+
write_variante(attr_name, params)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def translates?
|
23
|
+
included_modules.include?(InstanceMethods)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: variantable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Martin Ziserman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.0'
|
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: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: ''
|
70
|
+
email: martin@publidata.io
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- MIT-LICENSE
|
76
|
+
- README.md
|
77
|
+
- lib/variantable.rb
|
78
|
+
- lib/variantable/translates/instance_methods.rb
|
79
|
+
- lib/variantable/variantable.rb
|
80
|
+
- lib/variantable/version.rb
|
81
|
+
homepage: https://github.com/publidata/variantable
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.7.3
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: ''
|
105
|
+
test_files: []
|