discourse_dev 0.0.8 → 0.0.9

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: 78ead97c8c37d30f88d98a6e95a720647d73e564aa39872599488e3bcfc6fb0d
4
- data.tar.gz: eb83d5121929c789d926d69fc54c9d79f25d32f1f1177b524212699e5a0e901d
3
+ metadata.gz: 3c041cf9d05c586e547562729b749c5f86bc388a8311cd2a12fbb48e6ef3d56f
4
+ data.tar.gz: 69ddc047893ac6f4deeaf5f723eceb4317f6ba17a9d7b18bccfe520455286e76
5
5
  SHA512:
6
- metadata.gz: dcd86419248de6cfe03d3e09e9d3eb7f7c0e67ba460cd7a23dd49eeb605b8ad66db5055b1dbb6333588aac6a4ee00c08b9cd8d7113571bc904d888238bac8fe5
7
- data.tar.gz: 1e965d65532c23d0c8f5c0afd0e2d56f73b5d954219611416fb34bad0c8425f191caf47085122d7cb13234bdefed7da33ec7bcb6a000580d50ef44eb36353f09
6
+ metadata.gz: afcf13989b8677fe40aa5c80201d6b8fcc77bd1f7465bc03d8fbce153d009b2efd9a71de72f5950820d5f7b275ec7bbff16bed5d7b43c7264af02a382aa3b54f
7
+ data.tar.gz: dbad0056c7af12f508f623b7ddaac2ffbf04c452fb26580d257822fc34d990146cf4722375450934de3b78e2ec8e5f70f594e52764e3c68f6448f9c78eb71181
@@ -7,12 +7,15 @@ module DiscourseDev
7
7
  attr_reader :config, :default_config
8
8
 
9
9
  def initialize
10
- @default_config = YAML.load_file(File.join(File.expand_path(__dir__), "config.yml"))
10
+ default_file_path = File.join(File.expand_path(__dir__), "config.yml")
11
11
  file_path = File.join(Rails.root, "config", "dev.yml")
12
+ @default_config = YAML.load_file(default_file_path)
12
13
 
13
14
  if File.exists?(file_path)
14
15
  @config = YAML.load_file(file_path)
15
16
  else
17
+ puts "I did no detect a custom `config/dev.yml` file, creating one for you where you can amend defaults."
18
+ FileUtils.cp(default_file_path, file_path)
16
19
  @config = {}
17
20
  end
18
21
  end
@@ -6,9 +6,14 @@ require 'faker'
6
6
 
7
7
  module DiscourseDev
8
8
  class User < Record
9
+ attr_reader :images
9
10
 
10
11
  def initialize(count = DEFAULT_COUNT)
11
12
  super(::User, count)
13
+
14
+ # Using the stock avatar images from https://tinyfac.es
15
+ # Tiny Faces is a free crowd-sourced avatar gallery
16
+ @images = Dir[File.join(__dir__, '..', '..', 'avatars', '*.*')]
12
17
  end
13
18
 
14
19
  def data
@@ -31,6 +36,7 @@ module DiscourseDev
31
36
  def create!
32
37
  super do |user|
33
38
  user.activate
39
+ set_random_avatar(user)
34
40
  Faker::Number.between(from: 0, to: 2).times do
35
41
  group = Group.random
36
42
 
@@ -42,5 +48,48 @@ module DiscourseDev
42
48
  def self.random
43
49
  super(::User)
44
50
  end
51
+
52
+ def set_random_avatar(user)
53
+ return if images.blank?
54
+ return unless Faker::Boolean.boolean
55
+
56
+ avatar_index = Faker::Number.between(from: 0, to: images.count - 1)
57
+ avatar_path = images[avatar_index]
58
+ create_avatar(user, avatar_path)
59
+ @images.delete_at(avatar_index)
60
+ end
61
+
62
+ def create_avatar(user, avatar_path)
63
+ tempfile = copy_to_tempfile(avatar_path)
64
+ filename = "avatar#{File.extname(avatar_path)}"
65
+ upload = UploadCreator.new(tempfile, filename, type: "avatar").create_for(user.id)
66
+
67
+ if upload.present? && upload.persisted?
68
+ user.create_user_avatar
69
+ user.user_avatar.update(custom_upload_id: upload.id)
70
+ user.update(uploaded_avatar_id: upload.id)
71
+ else
72
+ STDERR.puts "Failed to upload avatar for user #{user.username}: #{avatar_path}"
73
+ STDERR.puts upload.errors.inspect if upload
74
+ end
75
+ rescue
76
+ STDERR.puts "Failed to create avatar for user #{user.username}: #{avatar_path}"
77
+ ensure
78
+ tempfile.close! if tempfile
79
+ end
80
+
81
+ private
82
+
83
+ def copy_to_tempfile(source_path)
84
+ extension = File.extname(source_path)
85
+ tmp = Tempfile.new(['discourse-upload', extension])
86
+
87
+ File.open(source_path) do |source_stream|
88
+ IO.copy_stream(source_stream, tmp)
89
+ end
90
+
91
+ tmp.rewind
92
+ tmp
93
+ end
45
94
  end
46
95
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DiscourseDev
4
- VERSION = "0.0.8"
4
+ VERSION = "0.0.9"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: discourse_dev
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vinoth Kannan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-07 00:00:00.000000000 Z
11
+ date: 2021-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faker
@@ -65,6 +65,19 @@ files:
65
65
  - LICENSE.txt
66
66
  - README.md
67
67
  - Rakefile
68
+ - avatars/03F55412-DE8A-4F83-AAA6-D67EE5CE48DA-200w.jpeg
69
+ - avatars/1C4EEDC2-FE9C-40B3-A2C9-A038873EE692-200w.jpeg
70
+ - avatars/26CFEFB3-21C8-49FC-8C19-8E6A62B6D2E0-200w.jpeg
71
+ - avatars/282A12CA-E0D7-4011-8BDD-1FAFAAB035F7-200w.jpeg
72
+ - avatars/2DDDE973-40EC-4004-ABC0-73FD4CD6D042-200w.jpeg
73
+ - avatars/344CFC24-61FB-426C-B3D1-CAD5BCBD3209-200w.jpeg
74
+ - avatars/852EC6E1-347C-4187-9D42-DF264CCF17BF-200w.jpeg
75
+ - avatars/A7299C8E-CEFC-47D9-939A-3C8CA0EA4D13-200w.jpeg
76
+ - avatars/AEF44435-B547-4B84-A2AE-887DFAEE6DDF-200w.jpeg
77
+ - avatars/B3CF5288-34B0-4A5E-9877-5965522529D6-200w.jpeg
78
+ - avatars/BA0CB1F2-8C79-4376-B13B-DD5FB8772537-200w.jpeg
79
+ - avatars/E0B4CAB3-F491-4322-BEF2-208B46748D4A-200w.jpeg
80
+ - avatars/FBEBF655-4886-455A-A4A4-D62B77DD419B-200w.jpeg
68
81
  - config/routes.rb
69
82
  - discourse_dev.gemspec
70
83
  - lib/discourse_dev.rb