discourse_dev 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +40 -4
- data/lib/discourse_dev/post.rb +1 -3
- data/lib/discourse_dev/record.rb +7 -10
- data/lib/discourse_dev/tag.rb +12 -0
- data/lib/discourse_dev/tasks/dev.rake +1 -1
- data/lib/discourse_dev/topic.rb +3 -1
- data/lib/discourse_dev/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b05da63d2ddcf5a7a100cfb9ab95e241a1273aa44f0eb8f0c0ea616793814470
|
4
|
+
data.tar.gz: d32bc205ef1072ee5d163cfe9626ffe7592a336286ecc9cd5fbe13f146a85f2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61a3aaa9e1cfa08499428e2369b456a466f3c51a7ea722917a3365a9a226f7067073ae6883ee1bd5e618f0f31a63f6e0cb4e74a04ab8478c3fb00f1c51ef7fde
|
7
|
+
data.tar.gz: 490c9ad8617b46d09d62b1772c829aa86cda11a5d898be73df6a4671e599c0eeba19f907e653db95f8f8f6d549cc90fd57b68f81dcfac5c5413461cb05dc60cc
|
data/README.md
CHANGED
@@ -2,14 +2,50 @@
|
|
2
2
|
|
3
3
|
![Gem](https://img.shields.io/gem/v/discourse_dev)
|
4
4
|
|
5
|
-
Rake helper tasks for Discourse developers.
|
5
|
+
Rake helper tasks for Discourse developers. These tasks can be used to populate random data like topics, groups, users, categories, and tags in your local `discourse_development` database.
|
6
6
|
|
7
7
|
## Available Rake Tasks
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
*
|
9
|
+
#### `dev:reset`
|
10
|
+
|
11
|
+
* db:migrate:reset
|
12
|
+
* db:drop
|
13
|
+
* db:create
|
14
|
+
* db:migrate
|
15
|
+
* dev:config
|
16
|
+
* admin:create
|
17
|
+
* dev:populate
|
18
|
+
* groups:populate
|
19
|
+
* users:populate
|
20
|
+
* categories:populate
|
21
|
+
* topics:populate
|
22
|
+
* tags:populate
|
23
|
+
|
24
|
+
The `rake dev:reset` command will just invoke other rake tasks in the above order. So it will completely recreate your development environment.
|
25
|
+
|
26
|
+
#### `dev:config`
|
27
|
+
|
28
|
+
Reloads the site settings from the dev.yml file.
|
29
|
+
|
30
|
+
#### `dev:populate`
|
31
|
+
|
32
|
+
Runs all of the sub-populate tasks.
|
33
|
+
|
34
|
+
#### `*:populate`
|
35
|
+
|
36
|
+
Populates the specified groups of records based on settings in dev.yml.
|
37
|
+
|
12
38
|
* `groups:populate`
|
13
39
|
* `users:populate`
|
14
40
|
* `categories:populate`
|
41
|
+
* `tags:populate`
|
15
42
|
* `topics:populate`
|
43
|
+
* `replies:populate`
|
44
|
+
|
45
|
+
## Configuration
|
46
|
+
|
47
|
+
In your local Discourse repository, this gem is included as a dependency. When you run the gem for the first time it will look for a `config/dev.yml` file and if it does not find one it will generate one from the default included with the gem. Here you can specify site settings which will override default site setting values, as well as configuration for how the local data is generated with this gem.
|
48
|
+
|
49
|
+
For category, group, post, tag, topic, and user you can specify the `count`, which is the maximum number of records that will be generated by the associated task.
|
50
|
+
|
51
|
+
For more in-depth information about configuration, consul the comments in the default `dev.yml` in the source code.
|
data/lib/discourse_dev/post.rb
CHANGED
@@ -63,8 +63,7 @@ module DiscourseDev
|
|
63
63
|
def populate!
|
64
64
|
generate_likes(topic.first_post)
|
65
65
|
|
66
|
-
@count.times do
|
67
|
-
@index = i
|
66
|
+
@count.times do
|
68
67
|
create!
|
69
68
|
end
|
70
69
|
end
|
@@ -86,7 +85,6 @@ module DiscourseDev
|
|
86
85
|
puts "Creating #{count} replies in '#{topic.title}'"
|
87
86
|
|
88
87
|
count.times do |i|
|
89
|
-
@index = i
|
90
88
|
begin
|
91
89
|
user = User.random
|
92
90
|
reply = Faker::DiscourseMarkdown.with_user(user.id) do
|
data/lib/discourse_dev/record.rb
CHANGED
@@ -20,7 +20,6 @@ module DiscourseDev
|
|
20
20
|
@model = model
|
21
21
|
@type = model.to_s
|
22
22
|
@count = count
|
23
|
-
@index = nil
|
24
23
|
end
|
25
24
|
|
26
25
|
def create!
|
@@ -30,7 +29,7 @@ module DiscourseDev
|
|
30
29
|
|
31
30
|
def populate!
|
32
31
|
if current_count >= @count
|
33
|
-
puts "Already have #{
|
32
|
+
puts "Already have #{current_count} #{type.downcase} records"
|
34
33
|
|
35
34
|
Rake.application.top_level_tasks.each do |task_name|
|
36
35
|
Rake::Task[task_name].reenable
|
@@ -38,12 +37,14 @@ module DiscourseDev
|
|
38
37
|
|
39
38
|
Rake::Task['dev:repopulate'].invoke
|
40
39
|
return
|
40
|
+
elsif current_count > 0
|
41
|
+
@count -= current_count
|
42
|
+
puts "There are #{current_count} #{type.downcase} records. Creating #{@count} more."
|
43
|
+
else
|
44
|
+
puts "Creating #{@count} sample #{type.downcase} records"
|
41
45
|
end
|
42
46
|
|
43
|
-
|
44
|
-
|
45
|
-
@count.times do |i|
|
46
|
-
@index = i
|
47
|
+
@count.times do
|
47
48
|
create!
|
48
49
|
putc "."
|
49
50
|
end
|
@@ -51,10 +52,6 @@ module DiscourseDev
|
|
51
52
|
puts
|
52
53
|
end
|
53
54
|
|
54
|
-
def index
|
55
|
-
@index
|
56
|
-
end
|
57
|
-
|
58
55
|
def current_count
|
59
56
|
model.count
|
60
57
|
end
|
data/lib/discourse_dev/tag.rb
CHANGED
@@ -11,6 +11,18 @@ module DiscourseDev
|
|
11
11
|
super(::Tag, DiscourseDev.config.tag[:count])
|
12
12
|
end
|
13
13
|
|
14
|
+
def create!
|
15
|
+
super
|
16
|
+
rescue ActiveRecord::RecordInvalid => e
|
17
|
+
# If the name is taken, try again
|
18
|
+
retry
|
19
|
+
end
|
20
|
+
|
21
|
+
def populate!
|
22
|
+
return unless SiteSetting.tagging_enabled
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
14
26
|
def data
|
15
27
|
{
|
16
28
|
name: Faker::Discourse.unique.tag,
|
@@ -42,6 +42,6 @@ task 'dev:repopulate' => ['db:load_config'] do |_, args|
|
|
42
42
|
if (answer == "" || answer.downcase == 'y')
|
43
43
|
Rake::Task['dev:reset'].invoke
|
44
44
|
else
|
45
|
-
puts "You can run `dev:reset`
|
45
|
+
puts "You can run `bin/rails dev:reset` to repopulate anytime."
|
46
46
|
end
|
47
47
|
end
|
data/lib/discourse_dev/topic.rb
CHANGED
@@ -45,7 +45,7 @@ module DiscourseDev
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def title
|
48
|
-
if
|
48
|
+
if current_count < I18n.t("faker.discourse.topics").count
|
49
49
|
Faker::Discourse.unique.topic
|
50
50
|
else
|
51
51
|
Faker::Lorem.unique.sentence(word_count: 5, supplemental: true, random_words_to_add: 4).chomp(".")
|
@@ -53,6 +53,8 @@ module DiscourseDev
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def tags
|
56
|
+
return unless SiteSetting.tagging_enabled
|
57
|
+
|
56
58
|
@tags = []
|
57
59
|
|
58
60
|
Faker::Number.between(from: @settings.dig(:tags, :min), to: @settings.dig(:tags, :max)).times do
|
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.2.
|
4
|
+
version: 0.2.1
|
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-
|
11
|
+
date: 2021-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faker
|