Module: Config

Defined in:
lib/jungle_path/app/config/config.rb

Overview

create a config.rb to override any of the jungle… values as needed:

Class Method Summary collapse

Class Method Details

.applicationObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/jungle_path/app/config/config.rb', line 49

def self.application
	jungle.application.id = 5
	jungle.application.root_dir = ::File.expand_path('..',::File.dirname(__FILE__))
	jungle.application.public_dir = File.join(jungle.application.root_dir, 'web_apps', 'public')
	jungle.application.name = 'jungle_path'
	jungle.application.url = nil
	jungle.application.logger = Logging.make_logger(jungle.application.root_dir, "#{jungle.application.name}_requests.log") # $stdout
	puts "application root dir: #{jungle.application.root_dir}"
	puts "application public dir: #{jungle.application.public_dir}"
end

.config_overrideObject



252
253
254
255
256
257
258
259
# File 'lib/jungle_path/app/config/config.rb', line 252

def self.config_override
	begin
		require_relative 'override'
		puts "[application root]/config/override.rb file was loaded."
	rescue LoadError => ex
		puts "warning!!! [application root]/config/override.rb file was not found, please create an override.rb file so that you can override default settings in 'config.rb'! override.rb should be in the same directory as config.rb."
	end
end

.dbObject



64
65
66
67
68
69
70
71
72
73
# File 'lib/jungle_path/app/config/config.rb', line 64

def self.db
	jungle.db.name = "jungle_path"
	jungle.db.type = "postgres"
	jungle.db.user_name = "junglepath"
	jungle.db.password =  nil
	jungle.db.host = "localhost"
	jungle.db.extensions = [:pg_json]
	jungle.db.port = nil # defaults to PostgreSQL default port of 5432 if nil.
	jungle.db.options = {max_connections: 4}
end

.debugObject



248
249
250
# File 'lib/jungle_path/app/config/config.rb', line 248

def self.debug
	jungle.debug.show_params = false
end

.environmentObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/jungle_path/app/config/config.rb', line 35

def self.environment
	# create 'environment.rb' file to override this setting:
	jungle.environment.name = "dev" # "dev", "stage", or "prod"
	begin
		require_relative 'environment'
		puts "[application root]/config/environment.rb file was loaded."
		puts "jungle.environment.name == '#{jungle.environment.name}'"
	rescue LoadError => ex
		puts "[application root]/config/environment.rb file was not found, defaulting to jungle.environment.name == '#{jungle.environment.name}'."
		puts "to override, create file ./config/environment.rb with one line like this:"
		puts "jungle.environment.name = 'stage' \# valid environments may be: 'dev', 'stage' or 'prod' or whatever you want to use :)"
	end
end

.initObject



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
# File 'lib/jungle_path/app/config/config.rb', line 8

def self.init
	# setting global config settings name 'jungle' on:
	JunglePath::Config.set_global_on # configuration will be global: can access 'jungle...' anywhere.
	environment
	application
	on_startup
	db
	smtp
	sms
	password_settings
	roles
	users
	schema_filters
	role_schema_filters
	role_query_filters
	restriction_query_filters
	user_query_filters
	role_table_filters
	restriction_table_filters
	user_table_filters
	#permissions_and_restrictions
	route_access
	debug
	config_override
	jungle.lock = true
end

.on_startupObject



60
61
62
# File 'lib/jungle_path/app/config/config.rb', line 60

def self.on_startup
	jungle.on_startup.run_database_migrations = false # Servers usually handle this on their own with deployments. For devs, may want to override in override.rb.
end

.password_settingsObject



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/jungle_path/app/config/config.rb', line 92

def self.password_settings
	jungle.password_settings = {
		length: {must_be_greater_than: 0, message: "Password length must be at least 1 characters."},
		#length: {must_be_greater_than: 7, message: "Password length must be at least 8 characters."},
		regular_expression_matches: [
			## {expression: /[[:alpha:]]/, message: "Password must have at least one alphabetical character."},
			## {expression: /[[:digit:]]/, message: "Password must have at least one numeric character."}
			#{expression: /\D/, message: "Password must have at least one alphabetical character."},
			#{expression: /\d/, message: "Password must have at least one numeric character."}
		]
	}
end

.restriction_query_filtersObject



192
193
194
195
196
197
198
199
200
# File 'lib/jungle_path/app/config/config.rb', line 192

def self.restriction_query_filters
	jungle.restriction_query_filters = lambda {|identity|
		filters = {
			#me_related:[
			#	{table_name: :user, sub_select: "select id from user where id = #{identity.user.id}"}
			#]
		}
	}
end

.restriction_table_filtersObject



218
219
220
221
222
223
224
225
# File 'lib/jungle_path/app/config/config.rb', line 218

def self.restriction_table_filters
	#jungle.restriction_table_filters = {
	#	me_related:[
	#		{table_name: :contact, replacement: :filter_contact}
	#	]
	#}
	jungle.restriction_table_filters = {}
end

.role_query_filtersObject



181
182
183
184
185
186
187
188
189
190
# File 'lib/jungle_path/app/config/config.rb', line 181

def self.role_query_filters
	jungle.role_query_filters = lambda {|identity|
		filters = {
			admin: [
				{table_name: :table_i_want_to_filter, sub_select: "select id from table_i_want_to_filter where a = b", use_not_in: false}
			]
			# more...
		}
	}
end

.role_schema_filtersObject



173
174
175
176
177
178
179
# File 'lib/jungle_path/app/config/config.rb', line 173

def self.role_schema_filters
	jungle.role_schema_filters = {
		root: :allow_all_tables,
		admin: :allow_all_tables,
		user: :hide_nonpublic_tables
	}
end

.role_table_filtersObject



208
209
210
211
212
213
214
215
216
# File 'lib/jungle_path/app/config/config.rb', line 208

def self.role_table_filters
	# Replace usage of a table in a query with the given view or parameterized function
	jungle.role_table_filters = {
		user: [
			{table_name: :contact, replacement: :filter_contact},
			{table_name: :test, replacement: :filter_test}
		]
	}
end

.rolesObject



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/jungle_path/app/config/config.rb', line 105

def self.roles
	jungle.roles = {
		root: {
			id: 0,
			name: :root,
			description: 'root can do anything',
			permissions: [:root],
			restrictions: []
		},
		admin: {
			id: 1,
			name: :admin,
			description: 'admin and add, edit and delete users, but not root users.',
			permissions: [:admin, :read],
			restrictions: []
		},
		user: {
			id: 2,
			name: :user,
			description: 'basic system user -- has read only access.',
			permissions: [:read, :assumable_user_identity],
			restrictions: [:query_only, :me_related]
		}
	}
end

.route_accessObject



231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/jungle_path/app/config/config.rb', line 231

def self.route_access
	jungle.route_access = {
		public: {
			get: {
				routes: ['/', '/app', '/admin', '/query', '/query/doc'],
				routes_start_with: ['/activate/', '/passwordresetcode/']
			}
		},
		authenticated: {
			get: {
				routes: ['/query/schema_tree'],
				routes_start_with: []
			}
		}
	}
end

.schema_filtersObject



166
167
168
169
170
171
# File 'lib/jungle_path/app/config/config.rb', line 166

def self.schema_filters
	jungle.schema_filters = {
		allow_all_tables: {allow: [table: /./]},
		hide_nonpublic_tables: {allow: [{table: /./}], deny: [{table: /^utility_/}, {table: /^temp_/}]}
	}
end

.smsObject

(texting)



86
87
88
89
90
# File 'lib/jungle_path/app/config/config.rb', line 86

def self.sms # (texting)
	jungle.sms.from_phone_number = nil
	jungle.sms. = nil
	jungle.sms.auth_token = nil
end

.smtpObject

(email)



75
76
77
78
79
80
81
82
83
84
# File 'lib/jungle_path/app/config/config.rb', line 75

def self.smtp # (email)
	jungle.smtp.host = "localhost"
	jungle.smtp.port = 25 #587 # 25
	jungle.smtp.domain_of_sender = 'mydomain.com'
	jungle.smtp.user_name = nil
	jungle.smtp.password = nil
	jungle.smtp.enable_tls = false
	jungle.smtp.authentication = nil
	jungle.smtp.from = nil # '[email protected]'
end

.user_query_filtersObject



202
203
204
205
206
# File 'lib/jungle_path/app/config/config.rb', line 202

def self.user_query_filters
	jungle.user_query_filters = lambda {|identity|
		filters = {}
	}
end

.user_table_filtersObject



227
228
229
# File 'lib/jungle_path/app/config/config.rb', line 227

def self.user_table_filters
	jungle.user_table_filters = {}
end

.usersObject



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/jungle_path/app/config/config.rb', line 131

def self.users
	jungle.users = {
		root: {
			id: 0,
			name: 'root',
			email: nil,
			phone: nil,
			active: true,
			user_name: :root,
			password: 'test',
			role: :root
		},
		admin: {
			id: 1,
			name: 'admin',
			email: nil,
			phone: nil,
			active: true,
			user_name: :admin,
			password: 'test',
			role: :admin
		},
		user: {
			id: 2,
			name: 'user',
			email: nil,
			phone: nil,
			active: true,
			user_name: :user,
			password: 'test',
			roles: :user
		}
	}
end