forked from theforeman/foreman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforeman.rb
48 lines (38 loc) · 1.17 KB
/
foreman.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require 'securerandom'
module Foreman
# generate a UUID
def self.uuid
SecureRandom.uuid
end
def self.uuid_regexp
@uuid_regexp ||= Regexp.new("^([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})$")
end
# does this look like a UUID?
def self.is_uuid?(str)
str.is_a?(String) && str.length == 36 && str.match?(uuid_regexp)
end
def self.in_rake?(*rake_tasks)
return false unless defined?(Rake) && Rake.respond_to?(:application)
Rake.application.top_level_tasks.any? do |running_rake_task|
rake_tasks.empty? || rake_tasks.any? { |rake_task| running_rake_task.start_with?(rake_task) }
end
end
def self.in_setup_db_rake?
in_rake?('db:create', 'db:migrate', 'db:drop')
end
def self.pending_migrations?
ActiveRecord::Base.connection.migration_context.needs_migration? || Foreman::Plugin.all.any?(&:pending_migrations)
end
def self.instance_id
Setting[:instance_id]
end
def self.instance_id=(value)
Setting[:instance_id] = value
end
def self.input_types_registry
@input_types_registry ||= Foreman::InputTypesRegistry.new
end
def self.settings
SettingRegistry.instance
end
end