tanoshimu_utils 2.0.0 → 2.0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e12e51d76c696e382e40ef43dc59ad97eb5479441925a8d8f638cf771344708e
4
- data.tar.gz: 885046472e52bcb839e2e77e76d623815a3de6b4b144ef9bff72c17ac3e5fa53
3
+ metadata.gz: c8d9925646696c1003bfd1550226d5f6b73b75dc66a18ab991a10b410b0f55a9
4
+ data.tar.gz: 1e39d2dd0a44993062c3872b4580f1360b426b8a979167537fb49b674f551a23
5
5
  SHA512:
6
- metadata.gz: 41ea0070f7a5e72c96b9e42ca810d65b5feeb1efb874081428287919e673e192c655278df64a7b299d710446c0a8b4aa09d93c448ffb8000ef8c342542325b73
7
- data.tar.gz: 4dc444e942cc31c5837d366b8b16436e46f5fec5390cdfecab297ae788d37fdd44231856e3c5be7822e35117c8053f80b13d1a73e3f2af399686393ef5da089a
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, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
42
+ After checking out the repo, build the gem and start a bash using Docker:
43
43
 
44
- 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).
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
 
@@ -3,3 +3,4 @@ require_relative 'concerns/identifiable'
3
3
  require_relative 'concerns/resource_fetch'
4
4
  require_relative 'concerns/respond_to_types'
5
5
  require_relative 'concerns/translatable'
6
+ require_relative 'concerns/has_translatable_field'
@@ -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 Config.uses_disk_storage?
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
@@ -1,3 +1,3 @@
1
1
  module TanoshimuUtils
2
- VERSION = '2.0.0'
2
+ VERSION = '2.0.2.1'
3
3
  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.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-01-10 00:00:00.000000000 Z
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: 6.0.0
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: 6.0.0
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.0.3
99
+ rubygems_version: 3.1.2
99
100
  signing_key:
100
101
  specification_version: 4
101
102
  summary: YourAnime.moe utilities