tanoshimu_utils 2.0.0 → 2.0.2.1
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: c8d9925646696c1003bfd1550226d5f6b73b75dc66a18ab991a10b410b0f55a9
|
4
|
+
data.tar.gz: 1e39d2dd0a44993062c3872b4580f1360b426b8a979167537fb49b674f551a23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d43f8fb59b4004767a9d50abad95009af843ce8ca158d3e352a48ecc36498e74d1c1dcc83b25811d0cc09e7433dacf385bd36bb5bf9fd6e1de95a4cbe084bbef
|
7
|
+
data.tar.gz: c5434201664cdd7a17cc633b70249a79c8cebafe55078f992a746e6042d201a18de0ec28dbba67f0690372e0936637437f93c7feeb71f8dcad79abe52aab1383
|
data/README.md
CHANGED
@@ -39,9 +39,24 @@ Or install it yourself as:
|
|
39
39
|
|
40
40
|
## Development
|
41
41
|
|
42
|
-
After checking out the repo,
|
42
|
+
After checking out the repo, build the gem and start a bash using Docker:
|
43
43
|
|
44
|
-
|
44
|
+
```bash
|
45
|
+
docker-compose build
|
46
|
+
docker-compose run gem bash
|
47
|
+
```
|
48
|
+
|
49
|
+
For testing using the rails console, make sure you're in the `test/dummy` folder:
|
50
|
+
|
51
|
+
```bash
|
52
|
+
cd test/dummy
|
53
|
+
rails db:reset # if you haven't done this yet
|
54
|
+
rails console
|
55
|
+
```
|
56
|
+
|
57
|
+
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).
|
58
|
+
|
59
|
+
You can push the gem inside the container. Caveat: you will need to log in every time you push the gem since the container will discard all system files when destroyed.
|
45
60
|
|
46
61
|
## Contributing
|
47
62
|
|
@@ -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
|
+
set_translatable_field = :"#{name}="
|
9
|
+
get_translatable_field = :"#{name}"
|
10
|
+
record_field = :"#{name}_record"
|
11
|
+
record_class = Object.const_get(name.capitalize)
|
12
|
+
current_class_name = self
|
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 = current_class_name.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
|
@@ -24,7 +24,7 @@ module TanoshimuUtils
|
|
24
24
|
attachment = resource_for(resource_name).attachment
|
25
25
|
return default_url if attachment.nil?
|
26
26
|
|
27
|
-
if
|
27
|
+
if Rails.configuration.uses_disk_storage
|
28
28
|
Rails.application.routes.url_helpers.rails_blob_url(attachment, only_path: true)
|
29
29
|
else
|
30
30
|
attachment.service_url(expires_in: expiry)
|
@@ -33,7 +33,8 @@ module TanoshimuUtils
|
|
33
33
|
send(:define_method, "#{resource_name}?") do
|
34
34
|
(fetch!(resource_name, default_url)&.attached?).present?
|
35
35
|
end
|
36
|
-
send(:define_method, "generate_#{resource_name}_url!") do
|
36
|
+
send(:define_method, "generate_#{resource_name}_url!") do |**options|
|
37
|
+
force = options[:force] || false
|
37
38
|
return nil unless persisted?
|
38
39
|
return true if send("#{resource_url}?") && !force
|
39
40
|
|
@@ -86,4 +87,4 @@ module TanoshimuUtils
|
|
86
87
|
end
|
87
88
|
end
|
88
89
|
end
|
89
|
-
end
|
90
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
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.1
|
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-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sqlite3
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -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
|