Class: DiscourseDev::Config
- Inherits:
-
Object
- Object
- DiscourseDev::Config
show all
- Defined in:
- lib/discourse_dev/config.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/discourse_dev/config.rb', line 9
def initialize
@default_config = YAML.load_file(File.join(File.expand_path(__dir__), "config.yml"))
file_path = File.join(Rails.root, "config", "dev.yml")
if File.exists?(file_path)
@config = YAML.load_file(file_path)
else
@config = {}
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
81
82
83
84
|
# File 'lib/discourse_dev/config.rb', line 81
def method_missing(name)
name = name.to_s
config[name] || default_config[name]
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
7
8
9
|
# File 'lib/discourse_dev/config.rb', line 7
def config
@config
end
|
#default_config ⇒ Object
Returns the value of attribute default_config.
7
8
9
|
# File 'lib/discourse_dev/config.rb', line 7
def default_config
@default_config
end
|
Instance Method Details
#create_admin_user ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/discourse_dev/config.rb', line 48
def create_admin_user
puts "Creating default admin user account..."
settings = config["admin"]
if settings.present?
email = settings["email"]
admin = ::User.create!(
email: email,
username: settings["username"] || UserNameSuggester.suggest(email),
password: settings["password"]
)
admin.grant_admin!
if admin.trust_level < 1
admin.change_trust_level!(1)
end
admin.email_tokens.update_all confirmed: true
admin.activate
else
Rake::Task['admin:create'].invoke
end
end
|
#set_seed ⇒ Object
72
73
74
75
|
# File 'lib/discourse_dev/config.rb', line 72
def set_seed
seed = self.seed || 1
Faker::Config.random = Random.new(seed)
end
|
#start_date ⇒ Object
77
78
79
|
# File 'lib/discourse_dev/config.rb', line 77
def start_date
DateTime.parse(config["start_date"] || default_config["start_date"])
end
|
#update! ⇒ Object
20
21
22
23
24
|
# File 'lib/discourse_dev/config.rb', line 20
def update!
update_site_settings
create_admin_user
set_seed
end
|
#update_site_settings ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/discourse_dev/config.rb', line 26
def update_site_settings
puts "Updating site settings..."
site_settings = config["site_settings"] || {}
site_settings.each do |key, value|
puts "#{key} = #{value}"
SiteSetting.set(key, value)
end
keys = site_settings.keys
default_config["site_settings"].each do |key, value|
next if keys.include?(key)
puts "#{key} = #{value}"
SiteSetting.set(key, value)
end
SiteSetting.refresh!
end
|