acts_as_hoc_avatarable 0.1.11 → 0.1.12

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
  SHA1:
3
- metadata.gz: 61f0c625a92f068094c187757eead22b53d87ccb
4
- data.tar.gz: af075fa8b0e1b09272b1c4008bb98d3589ca07d9
3
+ metadata.gz: d8a72a0640879c1d94563f6d787d7b7a3f564b60
4
+ data.tar.gz: 879bc30177e1d76fc0fce45dd592e3c75204074c
5
5
  SHA512:
6
- metadata.gz: b0e49f2567c0c52479f361cb54a4597a51d8567db4973371c523ba269624cfcc58624a7ee64d2fa4bd06ae319e07b48e633862cf375850434d3f87f5c4e286d3
7
- data.tar.gz: 9022cede3aec87a091d210fbf4de1c4b121d621090d6728c769ba9a8889f7215713f06fa975bf2c89ca5224115939a0904137423b1895967d9a92614ac227dac
6
+ metadata.gz: f3a3ed70d5128736bfed89075d00495de6488f2092d341f3cbd4d29d47a04e9681667d96147e6ffa0fa0bd8ba8132fb7015bce1a4050d55e46f8ef414df61172
7
+ data.tar.gz: fd50a10b0df2274fe50d708b69dd68b3effdec87b3f933b34a086cc6b6632123a4cbc520d4483f44dd59d58d9ff787f7d690861ff5410566e09d605502fa6529
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # ActsAsHocAvatarable
2
2
 
3
- Ease the use of active storage as avatar
3
+ Ease the use of ActiveStorage as an avatar for eg. user model.
4
+ This is specially made for API usage, where data is delivered as a base64 string.
5
+ Images can be resized on saving.
4
6
  This uses ActiveStorage, thus minimum rails version is 5.2
5
7
 
6
8
  ## Installation
@@ -15,28 +15,28 @@ module ActsAsHocAvatarable
15
15
  end
16
16
 
17
17
  def avatar_url
18
- return Rails.application.routes.url_helpers.rails_blob_url(avatar, host: (ActsAsHocAvatarable.configuration.default_host ||= "localhost:3000")) if avatar.attached?
19
- return "https://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(email)}" if (ActsAsHocAvatarable.configuration.fallback_to_gravatar ||= true)
18
+ return Rails.application.routes.url_helpers.rails_blob_url(avatar, host: ActsAsHocAvatarable.configuration.default_host) if avatar.attached?
19
+ return "https://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(email)}" if ActsAsHocAvatarable.configuration.fallback_to_gravatar
20
20
  return nil
21
21
  end
22
22
 
23
23
  def clear_avatar
24
24
  if remove_avatar == '1'
25
- avatar_contents = nil
25
+ @avatar_contents = nil
26
26
  avatar.purge_later
27
27
  end
28
28
  end
29
29
 
30
30
  def parse_avatar
31
31
  # If directly uploaded
32
- unless avatar_contents.nil? || avatar_contents[/(image\/[a-z]{3,4})|(application\/[a-z]{3,4})/] == ''
33
- content_type = avatar_contents[/(image\/[a-z]{3,4})|(application\/[a-z]{3,4})/]
32
+ unless avatar_contents.nil? || avatar_contents[/(image\/[a-z]{3,4})/] == ''
33
+ content_type = avatar_contents[/(image\/[a-z]{3,4})/]
34
34
  content_type = content_type[/\b(?!.*\/).*/]
35
- contents = avatar_contents.sub /data:((image|application)\/.{3,}),/, ''
35
+ contents = avatar_contents.sub /data:((image)\/.{3,}),/, ''
36
36
  decoded_data = Base64.decode64(contents)
37
37
  mini_magick = MiniMagick::Image.read(decoded_data)
38
- if (ActsAsHocAvatarable.configuration.resize_on_create ||= true)
39
- mini_magick.resize (ActsAsHocAvatarable.configuration.resize_size ||= "100x100>")
38
+ if ActsAsHocAvatarable.configuration.resize_on_create
39
+ mini_magick.resize (ActsAsHocAvatarable.configuration.resize_size)
40
40
  end
41
41
  decoded_data = mini_magick.to_blob
42
42
  filename = avatar_name || "avatar_#{Time.zone.now.to_i}.#{content_type}"
@@ -5,6 +5,10 @@ module ActsAsHocAvatarable
5
5
  attr_accessor :fallback_to_gravatar
6
6
  attr_accessor :default_host
7
7
  def initialize
8
+ @resize_on_create = true
9
+ @resize_size = "400x400>"
10
+ @fallback_to_gravatar = true
11
+ @default_host = "localhost:3000"
8
12
  end
9
13
  end
10
14
  end
@@ -1,3 +1,3 @@
1
1
  module ActsAsHocAvatarable
2
- VERSION = "0.1.11"
2
+ VERSION = "0.1.12"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_hoc_avatarable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gert Lavsen