Class: Subtrac::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/subtrac/config.rb

Constant Summary collapse

USER_CONFIG_FILE =
'config/user.yml'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.dataObject

Returns the value of attribute data.



14
15
16
# File 'lib/subtrac/config.rb', line 14

def data
  @data
end

Class Method Details

.apache_conf_dirObject



149
150
151
# File 'lib/subtrac/config.rb', line 149

def apache_conf_dir
  @apache_conf_dir ||= @data[:apache_conf_dir]
end

.apache_conf_dir=(name) ⇒ Object



153
154
155
# File 'lib/subtrac/config.rb', line 153

def apache_conf_dir=(name)
  @data[:apache_conf_dir] = @apache_conf_dir = name
end

.auth_dirObject



177
178
179
# File 'lib/subtrac/config.rb', line 177

def auth_dir
  @auth_dir ||= File.join(install_dir,@data[:dirs][:auth])
end

.clientObject



82
83
84
# File 'lib/subtrac/config.rb', line 82

def client
  @client
end

.client=(name) ⇒ Object



86
87
88
# File 'lib/subtrac/config.rb', line 86

def client=(name)
  @client = name
end

.confirm_or_update(prop, name) ⇒ Object

confirms the current value with the user or accepts a new value if required



63
64
65
66
67
68
69
70
71
72
# File 'lib/subtrac/config.rb', line 63

def confirm_or_update(prop, name)
  method(prop).call # initialise the property
  current_value = instance_variable_get("@#{prop}")
  accept_default = agree("The default value for #{prop} is \"#{current_value}\". Is this ok? [y/n]")
  if !accept_default then
    answer = ask("What would you like to change it to?")
    send("#{prop}=", answer)
    #instance_variable_set(prop, answer)
  end
end

.default_clientObject



107
108
109
# File 'lib/subtrac/config.rb', line 107

def default_client
  @default_client ||= @data[:default_client]
end

.default_client=(name) ⇒ Object



111
112
113
# File 'lib/subtrac/config.rb', line 111

def default_client=(name)
  @data[:default_client] = @default_client = name
end

.default_projectObject



115
116
117
# File 'lib/subtrac/config.rb', line 115

def default_project
  @default_project ||= @data[:default_project]
end

.default_project=(name) ⇒ Object



119
120
121
# File 'lib/subtrac/config.rb', line 119

def default_project=(name)
  @data[:default_project] = @default_project = name
end

.docs_dirObject



157
158
159
# File 'lib/subtrac/config.rb', line 157

def docs_dir
  @docs_dir ||= File.join(install_dir,@data[:dirs][:docs])
end

.enable_ldapObject

LDAP



195
196
197
# File 'lib/subtrac/config.rb', line 195

def enable_ldap
  @enable_ldap ||= @data[:ldap][:enable]
end

.enable_ldap=(value) ⇒ Object



199
200
201
# File 'lib/subtrac/config.rb', line 199

def enable_ldap=(value)
  @data[:ldap][:enable] = @enable_ldap = value
end

.enable_smtpObject

SMTP



273
274
275
# File 'lib/subtrac/config.rb', line 273

def enable_smtp
  @enable_smtp ||= @data[:smtp][:enable]
end

.enable_smtp=(value) ⇒ Object



277
278
279
# File 'lib/subtrac/config.rb', line 277

def enable_smtp=(value)
  @data[:smtp][:enable] = @enable_smtp = value
end

.get_bindingObject



20
21
22
# File 'lib/subtrac/config.rb', line 20

def get_binding
  binding
end

.initializeObject



16
17
18
# File 'lib/subtrac/config.rb', line 16

def initialize()
  puts "config/initialize"
end

.install_dirObject



140
141
142
# File 'lib/subtrac/config.rb', line 140

def install_dir
  @install_dir ||= File.expand_path(@data[:installation_dir])
end

.install_dir=(name) ⇒ Object



144
145
146
147
# File 'lib/subtrac/config.rb', line 144

def install_dir=(name)
  puts "Setting new install_dir variable to #{name}"
  @data[:installation_dir] = @install_dir = name
end

.ldap_basednObject



219
220
221
# File 'lib/subtrac/config.rb', line 219

def ldap_basedn
  @ldap_basedn ||= @data[:ldap][:basedn]
end

.ldap_basedn=(value) ⇒ Object



223
224
225
# File 'lib/subtrac/config.rb', line 223

def ldap_basedn=(value)
  @data[:ldap][:basedn] = @ldap_basedn = value
end

.ldap_bind_passwdObject



263
264
265
# File 'lib/subtrac/config.rb', line 263

def ldap_bind_passwd
  @ldap_bind_passwd ||= @data[:ldap][:bind_passwd]
end

.ldap_bind_passwd=(value) ⇒ Object



267
268
269
# File 'lib/subtrac/config.rb', line 267

def ldap_bind_passwd=(value)
  @data[:ldap][:bind_passwd] = @ldap_bind_passwd = value
end

.ldap_bind_userObject



255
256
257
# File 'lib/subtrac/config.rb', line 255

def ldap_bind_user
  @ldap_bind_user ||= @data[:ldap][:bind_user]
end

.ldap_bind_user=(value) ⇒ Object



259
260
261
# File 'lib/subtrac/config.rb', line 259

def ldap_bind_user=(value)
  @data[:ldap][:bind_user] = @ldap_bind_user = value
end

.ldap_group_rdnObject



235
236
237
# File 'lib/subtrac/config.rb', line 235

def ldap_group_rdn
  @ldap_group_rdn ||= @data[:ldap][:group_rdn]
end

.ldap_group_rdn=(value) ⇒ Object



239
240
241
# File 'lib/subtrac/config.rb', line 239

def ldap_group_rdn=(value)
  @data[:ldap][:group_rdn] = @ldap_group_rdn = value
end

.ldap_hostObject



203
204
205
# File 'lib/subtrac/config.rb', line 203

def ldap_host
  @ldap_host ||= @data[:ldap][:host]
end

.ldap_host=(value) ⇒ Object



207
208
209
# File 'lib/subtrac/config.rb', line 207

def ldap_host=(value)
  @data[:ldap][:host] = @ldap_host = value
end

.ldap_portObject



211
212
213
# File 'lib/subtrac/config.rb', line 211

def ldap_port
  @ldap_port ||= @data[:ldap][:port]
end

.ldap_port=(value) ⇒ Object



215
216
217
# File 'lib/subtrac/config.rb', line 215

def ldap_port=(value)
  @data[:ldap][:port] = @ldap_port = value
end

.ldap_store_bindObject



243
244
245
# File 'lib/subtrac/config.rb', line 243

def ldap_store_bind
  @ldap_store_bind ||= @data[:ldap][:store_bind]
end

.ldap_store_bind=(value) ⇒ Object



247
248
249
# File 'lib/subtrac/config.rb', line 247

def ldap_store_bind=(value)
  @data[:ldap][:store_bind] = @ldap_store_bind = value
end

.ldap_user_rdnObject



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

def ldap_user_rdn
  @ldap_user_rdn ||= @data[:ldap][:user_rdn]
end

.ldap_user_rdn=(value) ⇒ Object



231
232
233
# File 'lib/subtrac/config.rb', line 231

def ldap_user_rdn=(value)
  @data[:ldap][:user_rdn] = @ldap_user_rdn = value
end

.loadObject

Loads the configuration YML file



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/subtrac/config.rb', line 29

def load
  # TODO: We need to refactor this code so it will load the default configuration only if one has not been created
  puts "\n==== Loading configuration file ===="
  # load configuration file
  file_path = File.join(subtrac_path, USER_CONFIG_FILE)
  file_path = File.join(subtrac_path,"/config/config.yml") if not File.exists?(file_path)
  puts "Attempting to read config file: #{file_path}"
  begin
    yamlFile = YAML.load(File.read(file_path))
  rescue Exception => e
    raise StandardError, "Config #{file_path} could not be loaded."
  end
  if yamlFile
    if yamlFile[SUBTRAC_ENV]
      @data = yamlFile[SUBTRAC_ENV]
      @loaded = true
    else
      raise StandardError, "config/config.yml exists, but doesn't have a configuration for #{SUBTRAC_ENV}."
    end
  else
    raise StandardError, "config/config.yml does not exist."
  end
  say("Configuration loaded successfully...")
end

.loaded?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/subtrac/config.rb', line 24

def loaded?
  @loaded ||= false
end

.locations_dirObject



181
182
183
# File 'lib/subtrac/config.rb', line 181

def locations_dir
  @locations_dir ||= File.join(install_dir,@data[:dirs][:locations])
end

.log_dirObject



173
174
175
# File 'lib/subtrac/config.rb', line 173

def log_dir
  @log_dir ||= File.join(install_dir,@data[:dirs][:log])
end

.projectObject



74
75
76
# File 'lib/subtrac/config.rb', line 74

def project
  @project
end

.project=(name) ⇒ Object



78
79
80
# File 'lib/subtrac/config.rb', line 78

def project=(name)
  @project = name
end

.public_pathObject



128
129
130
# File 'lib/subtrac/config.rb', line 128

def public_path
  @public_path ||= self.root ? File.join(self.root, "public") : "public"
end

.public_path=(path) ⇒ Object



132
133
134
# File 'lib/subtrac/config.rb', line 132

def public_path=(path)
  @public_path = path
end

.rootObject

Filesystem directories



124
125
126
# File 'lib/subtrac/config.rb', line 124

def root
  Pathname.new(SUBTRAC_ROOT) if defined?(SUBTRAC_ROOT)
end

.saveObject

Write the changes configuration to disk



55
56
57
58
59
60
# File 'lib/subtrac/config.rb', line 55

def save
  # save the things that might have changed    
  file_path = File.join(subtrac_path, USER_CONFIG_FILE)
  user_config = {SUBTRAC_ENV => @data}
  open(file_path, 'w') {|f| YAML.dump(user_config, f)}
end

.server_hostnameObject



99
100
101
# File 'lib/subtrac/config.rb', line 99

def server_hostname
  @server_hostname ||= @data[:server_hostname]
end

.server_hostname=(name) ⇒ Object



103
104
105
# File 'lib/subtrac/config.rb', line 103

def server_hostname=(name)
  @data[:server_hostname] = @server_hostname = name
end

.server_nameObject

User configured options



91
92
93
# File 'lib/subtrac/config.rb', line 91

def server_name
  @server_name ||= @data[:server_name]
end

.server_name=(name) ⇒ Object



95
96
97
# File 'lib/subtrac/config.rb', line 95

def server_name=(name)
  @data[:server_name] = @server_name = name
end

.subtrac_pathObject



136
137
138
# File 'lib/subtrac/config.rb', line 136

def subtrac_path
  @subtrac_path ||= self.root ? File.join(self.root, "subtrac") : "subtrac"
end

.svn_dirObject



161
162
163
# File 'lib/subtrac/config.rb', line 161

def svn_dir
  @svn_dir ||= File.join(install_dir,@data[:dirs][:svn])
end

.svn_urlObject

Urls



186
187
188
# File 'lib/subtrac/config.rb', line 186

def svn_url
  @svn_url ||= @data[:urls][:svn]
end

.temp_dirObject



169
170
171
# File 'lib/subtrac/config.rb', line 169

def temp_dir
  @temp_dir ||= File.join(install_dir,@data[:dirs][:temp])
end

.trac_dirObject



165
166
167
# File 'lib/subtrac/config.rb', line 165

def trac_dir
  @trac_dir ||= File.join(install_dir,@data[:dirs][:trac])
end

.trac_permissionsObject



190
191
192
# File 'lib/subtrac/config.rb', line 190

def trac_permissions
  @trac_permissions ||= @data[:trac][:permissions]
end