tanoshimu_utils 2.0.1.1 → 2.0.2
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
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ceb19bd51af668df54c36d3a3816736fa30429d0ef102a2a2988e2fb69f683b5
|
4
|
+
data.tar.gz: bd6076c5b8bd97f004ff970f2943cb3160a7ad7f2687554f5b01f05ac209838f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 610bf66297ca0e5e916d1257e8c28b9ab9b4fa8969e23c0f641ac43bbd0ca7eda0c9a62edc9253b99656c1c656b3c85c6d7ab0f30fb6eb74bb3789765cc31c74
|
7
|
+
data.tar.gz: 899a1446770351dfa4a53ba89e18c0b315f8672efb497072ee866e02d056efd394f3ae42122063ccb7f609f462ef7245bf1ddd8362123aee5df6b88e29ccc6f6
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module TanoshimuUtils
|
2
|
+
module Concerns
|
3
|
+
module HasTranslatableField
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
class_methods do
|
7
|
+
def has_translatable_field(name, foreign_key: :model_id)
|
8
|
+
p "USING METHOD"
|
9
|
+
set_translatable_field = :"#{name}="
|
10
|
+
get_translatable_field = :"#{name}"
|
11
|
+
record_field = :"#{name}_record"
|
12
|
+
record_class = Object.const_get(name.capitalize)
|
13
|
+
|
14
|
+
send(:define_method, get_translatable_field) do
|
15
|
+
instance_variable_get("@#{name}") ||
|
16
|
+
instance_variable_set("@#{name}", send(record_field)&.value)
|
17
|
+
end
|
18
|
+
|
19
|
+
send(:define_method, set_translatable_field) do |new_record_field|
|
20
|
+
return unless new_record_field.kind_of?(record_class)
|
21
|
+
|
22
|
+
new_record_field.used_by_model = record_class.table_name
|
23
|
+
new_record_field.send(:"#{foreign_key}=", self.id)
|
24
|
+
self.send(:"#{record_field}=", new_record_field)
|
25
|
+
end
|
26
|
+
|
27
|
+
has_one(
|
28
|
+
record_field,
|
29
|
+
class_name: record_class.to_s,
|
30
|
+
foreign_key: foreign_key,
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tanoshimu_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akinyele Cafe-Febrissy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- lib/tanoshimu_utils.rb
|
67
67
|
- lib/tanoshimu_utils/concerns.rb
|
68
68
|
- lib/tanoshimu_utils/concerns/get_record.rb
|
69
|
+
- lib/tanoshimu_utils/concerns/has_translatable_field.rb
|
69
70
|
- lib/tanoshimu_utils/concerns/identifiable.rb
|
70
71
|
- lib/tanoshimu_utils/concerns/resource_fetch.rb
|
71
72
|
- lib/tanoshimu_utils/concerns/respond_to_types.rb
|
@@ -95,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
96
|
- !ruby/object:Gem::Version
|
96
97
|
version: '0'
|
97
98
|
requirements: []
|
98
|
-
rubygems_version: 3.
|
99
|
+
rubygems_version: 3.1.2
|
99
100
|
signing_key:
|
100
101
|
specification_version: 4
|
101
102
|
summary: YourAnime.moe utilities
|