Class: Utopia::Setup

Inherits:
Object
  • Object
show all
Defined in:
lib/utopia/setup.rb

Overview

Used for setting up a Utopia web application, typically via config/environment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, *arguments, **options) ⇒ Setup

Returns a new instance of Setup.



33
34
35
36
37
# File 'lib/utopia/setup.rb', line 33

def initialize(root, *arguments, **options)
	@root = root
	
	super(*arguments, **options)
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



39
40
41
# File 'lib/utopia/setup.rb', line 39

def root
  @root
end

Instance Method Details

#apply!Object



79
80
81
82
83
84
85
# File 'lib/utopia/setup.rb', line 79

def apply!
	add_load_path('lib')
	
	apply_environment
	
	require_relative '../utopia'
end

#config_rootObject



41
42
43
# File 'lib/utopia/setup.rb', line 41

def config_root
	File.expand_path("config", @root)
end

#development?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/utopia/setup.rb', line 57

def development?
	Variant.for(:utopia) == :development
end

#production?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/utopia/setup.rb', line 49

def production?
	Variant.for(:utopia) == :production
end

#secret_for(key) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/utopia/setup.rb', line 65

def secret_for(key)
	secret = ENV["UTOPIA_#{key.upcase}_SECRET"]
	
	if secret.nil? || secret.empty?
		secret = SecureRandom.hex(32)
		
		Utopia.logger.warn(self) do
			"Generating transient #{key} secret: #{secret.inspect}"
		end
	end
	
	return secret
end

#site_rootObject



45
46
47
# File 'lib/utopia/setup.rb', line 45

def site_root
	@root
end

#staging?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/utopia/setup.rb', line 53

def staging?
	Variant.for(:utopia) == :staging
end

#testing?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/utopia/setup.rb', line 61

def testing?
	Variant.for(:utopia) == :testing
end