Class: Houston::Configuration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/configuration.rb', line 14

def initialize
  @root = Rails.root
  @modules = []
  @gems = []
  @navigation_renderers = {}
  @user_options = {}
  @available_project_features = {}
  @ticket_types = {}
  @authentication_strategy = :database
  @authentication_strategy_configuration = {}
  @ticket_tracker_configuration = {}
  @ci_server_configuration = {}
  @error_tracker_configuration = {}
  @timers = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



443
444
445
446
# File 'lib/configuration.rb', line 443

def method_missing(name, *args, &block)
  puts "\e[33mMissing Configuration option: #{name}\e[0m"
  nil
end

Instance Attribute Details

#authentication_strategy_configurationObject (readonly)

Returns the value of attribute authentication_strategy_configuration.



257
258
259
# File 'lib/configuration.rb', line 257

def authentication_strategy_configuration
  @authentication_strategy_configuration
end

#modulesObject (readonly)

Returns the value of attribute modules.



343
344
345
# File 'lib/configuration.rb', line 343

def modules
  @modules
end

#tag_mapObject (readonly)

Returns the value of attribute tag_map.



380
381
382
# File 'lib/configuration.rb', line 380

def tag_map
  @tag_map
end

#timersObject (readonly)

Returns the value of attribute timers.



12
13
14
# File 'lib/configuration.rb', line 12

def timers
  @timers
end

Instance Method Details

#abilities(&block) ⇒ Object

Permissions



286
287
288
# File 'lib/configuration.rb', line 286

def abilities(&block)
  @abilities_block = block
end

#add_navigation_renderer(name, &block) ⇒ Object



139
140
141
# File 'lib/configuration.rb', line 139

def add_navigation_renderer(name, &block)
  @navigation_renderers[name] = block
end

#add_project_feature(slug, &block) ⇒ Object

Raises:

  • (ArgumentError)


174
175
176
177
178
179
180
181
182
183
184
# File 'lib/configuration.rb', line 174

def add_project_feature(slug, &block)
  dsl = ProjectFeatureDsl.new
  dsl.instance_eval(&block)
  feature = dsl.feature
  feature.slug = slug
  raise ArgumentError, "Project Feature must supply name, but #{slug.inspect} doesn't" unless feature.name
  raise ArgumentError, "Project Feature must supply icon, but #{slug.inspect} doesn't" unless feature.icon
  raise ArgumentError, "Project Feature must supply path lambda, but #{slug.inspect} doesn't" unless feature.path_block

  @available_project_features[slug] = feature
end

#add_user_option(slug, &block) ⇒ Object



149
150
151
152
153
154
155
156
# File 'lib/configuration.rb', line 149

def add_user_option(slug, &block)
  dsl = FormBuilderDsl.new
  dsl.instance_eval(&block)
  form = dsl.form
  form.slug = slug

  @user_options[slug] = form
end

#at(time, name, options = {}, &block) ⇒ Object



407
408
409
# File 'lib/configuration.rb', line 407

def at(time, name, options={}, &block)
  @timers.push [:cron, time, name, options, block]
end

#authentication_strategy(strategy = nil, &block) ⇒ Object

Authentication options



251
252
253
254
255
256
# File 'lib/configuration.rb', line 251

def authentication_strategy(strategy=nil, &block)
  @authentication_strategy = strategy if strategy
  @authentication_strategy_configuration = HashDsl.hash_from_block(block) if block_given?

  @authentication_strategy
end

#change_tags(*args) ⇒ Object

Configuration for Releases



361
362
363
364
365
366
367
368
369
370
371
372
373
374
# File 'lib/configuration.rb', line 361

def change_tags(*args)
  if args.any?
    @tag_map = {}
    args.flatten.each_with_index do |hash, position|
      Tag.new(hash.pick(:name, :color).merge(slug: hash[:as], position: position)).tap do |tag|
        @tag_map[tag.slug] = tag
        hash.fetch(:aliases, []).each do |slug|
          @tag_map[slug] = tag
        end
      end
    end
  end
  (@tag_map ||= {}).values.uniq
end

#configure_abilities(context, user) ⇒ Object



294
295
296
# File 'lib/configuration.rb', line 294

def configure_abilities(context, user)
  context.instance_exec(user, &@abilities_block)
end

#default_roleObject



204
205
206
# File 'lib/configuration.rb', line 204

def default_role
  "Guest"
end

#defines_abilities?Boolean

Returns:

  • (Boolean)


290
291
292
# File 'lib/configuration.rb', line 290

def defines_abilities?
  @abilities_block.present?
end

#devise_configurationObject



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/configuration.rb', line 259

def devise_configuration
  # Include default devise modules. Others available are:
  #      :registerable,
  #      :encryptable,
  #      :confirmable,
  #      :lockable,
  #      :timeoutable,
  #      :omniauthable

  configuration = [:database_authenticatable]
  unless Rails.env.test? # <-- !todo: control when custom strategies are employed in the test suite
    configuration << :ldap_authenticatable if authentication_strategy == :ldap
  end
  configuration.concat [
   :recoverable,
   :rememberable,
   :trackable,
   :validatable,
   :invitable ]
end

#engineyard(&block) ⇒ Object



124
125
126
127
# File 'lib/configuration.rb', line 124

def engineyard(&block)
  @engineyard = HashDsl.hash_from_block(block) if block_given?
  @engineyard ||= {}
end

#environments(*args) ⇒ Object



194
195
196
197
# File 'lib/configuration.rb', line 194

def environments(*args)
  @environments = args if args.any?
  @environments ||= []
end

#every(interval, name, options = {}, &block) ⇒ Object



411
412
413
# File 'lib/configuration.rb', line 411

def every(interval, name, options={}, &block)
  @timers.push [:every, interval, name, options, block]
end

#fetch_tag(slug) ⇒ Object



376
377
378
# File 'lib/configuration.rb', line 376

def fetch_tag(slug)
  tag_map.fetch(slug, NullTag.instance)
end

#get_navigation_renderer(name) ⇒ Object



143
144
145
# File 'lib/configuration.rb', line 143

def get_navigation_renderer(name)
  @navigation_renderers.fetch(name)
end

#get_project_feature(slug) ⇒ Object



170
171
172
# File 'lib/configuration.rb', line 170

def get_project_feature(slug)
  @available_project_features[slug]
end

#github(&block) ⇒ Object



325
326
327
328
# File 'lib/configuration.rb', line 325

def github(&block)
  @github_configuration = HashDsl.hash_from_block(block) if block_given?
  @github_configuration ||= {}
end

#host(*args) ⇒ Object



68
69
70
71
# File 'lib/configuration.rb', line 68

def host(*args)
  @host = args.first if args.any?
  @host ||= nil
end

#identify_committers(commit = nil, &block) ⇒ Object



237
238
239
240
241
242
243
# File 'lib/configuration.rb', line 237

def identify_committers(commit=nil, &block)
  if block_given?
    @identify_committers_proc = block
  elsif commit
    @identify_committers_proc ? Array(@identify_committers_proc.call(commit)) : [commit.committer_email]
  end
end

#key_dependencies(&block) ⇒ Object



388
389
390
391
392
393
394
395
# File 'lib/configuration.rb', line 388

def key_dependencies(&block)
  if block_given?
    dependencies = Houston::Dependencies.new
    dependencies.instance_eval(&block)
    @dependencies = dependencies.values
  end
  @dependencies || []
end

#keypairObject



101
102
103
# File 'lib/configuration.rb', line 101

def keypair
  root.join("config", "keypair.pem")
end

#load(glob) ⇒ Object



419
420
421
422
423
424
425
426
# File 'lib/configuration.rb', line 419

def load(glob)
  __file__ = caller[0].split(":")[0]
  glob << ".rb" unless glob.end_with? ".rb"
  Dir.glob("#{File.dirname(__file__)}/#{glob}").each do |file|
    next if File.directory?(file)
    require file
  end
end

#mailer_fromObject



87
88
89
90
91
92
93
94
# File 'lib/configuration.rb', line 87

def mailer_from
  require "mail"

  Mail::Address.new.tap do |email|
    email.display_name = title
    email.address = mailer_sender
  end.to_s
end

#mailer_sender(*args) ⇒ Object



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

def mailer_sender(*args)
  if args.any?
    @mailer_sender = args.first
    (Rails.application.config.action_mailer.default_options ||= {}).merge!(from: @mailer_sender)
  end
  @mailer_sender ||= nil
end

#module(module_name) ⇒ Object



350
351
352
353
# File 'lib/configuration.rb', line 350

def module(module_name)
  module_name = module_name.to_s
  modules.detect { |mod| mod.name == module_name }
end


134
135
136
137
# File 'lib/configuration.rb', line 134

def navigation(*args)
  @navigation = args if args.any?
  @navigation ||= []
end

#on(event, &block) ⇒ Object

Events



403
404
405
# File 'lib/configuration.rb', line 403

def on(event, &block)
  Houston.observer.on(event, &block)
end

#parallelization(*args) ⇒ Object



105
106
107
108
# File 'lib/configuration.rb', line 105

def parallelization(*args)
  @parallelization = args.first if args.any?
  @parallelization ||= :off
end

#parallelize?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/configuration.rb', line 110

def parallelize?
  parallelization == :on
end

#parse_ticket_description(ticket = nil, &block) ⇒ Object



229
230
231
232
233
234
235
# File 'lib/configuration.rb', line 229

def parse_ticket_description(ticket=nil, &block)
  if block_given?
    @parse_ticket_description_proc = block
  elsif ticket
    @parse_ticket_description_proc.call(ticket) if @parse_ticket_description_proc
  end
end

#passphrase(*args) ⇒ Object



96
97
98
99
# File 'lib/configuration.rb', line 96

def passphrase(*args)
  @passphrase = args.first if args.any?
  @passphrase ||= nil
end

#project_categories(*args) ⇒ Object



129
130
131
132
# File 'lib/configuration.rb', line 129

def project_categories(*args)
  @project_categories = args if args.any?
  @project_categories ||= []
end

#project_colors(*args) ⇒ Object



188
189
190
191
192
# File 'lib/configuration.rb', line 188

def project_colors(*args)
  new_hash = Hash.new(ColorValue.new("505050"))
  @project_colors = args.first.each_with_object(new_hash) { |(key, hex), hash| hash[key] = ColorValue.new(hex) } if args.any?
  @project_colors ||= new_hash
end

#project_features(*args) ⇒ Object



164
165
166
167
168
# File 'lib/configuration.rb', line 164

def project_features(*args)
  @project_features = args if args.any?
  return @available_project_features.keys unless @project_features
  @project_features & @available_project_features.keys
end

#project_roles(*args) ⇒ Object



208
209
210
211
# File 'lib/configuration.rb', line 208

def project_roles(*args)
  @project_roles = args if args.any?
  ["Follower"] + (@project_roles ||= [])
end

#roles(*args) ⇒ Object



199
200
201
202
# File 'lib/configuration.rb', line 199

def roles(*args)
  @roles = args if args.any?
  ["Guest"] + (@roles ||= [])
end

#root(*args) ⇒ Object

Global configuration



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/configuration.rb', line 36

def root(*args)
  return @root if args.none?
  @root = args.first

  # Keep structure.sql in instances' db directory
  ActiveRecord::Tasks::DatabaseTasks.db_dir = root.join("db")

  # Configure Houston
  Houston::Application.paths["config/database"] = root.join("config/database.yml")
  Houston::Application.paths["public"] = root.join("public")
  Houston::Application.paths["log"] = root.join("log/#{Rails.env}.log")
  Houston::Application.paths["tmp"] = root.join("tmp")
  Houston::Application.paths["config/environments"] << root.join("config/environments")

  # TODO: finish this
  Rails.application.assets = Sprockets::Environment.new(root) do |env|
    env.version = Rails.env

    path = "#{Houston.root}/tmp/cache/assets/#{Rails.env}"
    env.cache = Sprockets::Cache::FileStore.new(path)

    env.context_class.class_eval do
      include ::Sprockets::Rails::Helper
    end
  end
end

#s3(&block) ⇒ Object



119
120
121
122
# File 'lib/configuration.rb', line 119

def s3(&block)
  @s3 = HashDsl.hash_from_block(block) if block_given?
  @s3 ||= {}
end

#smtp(&block) ⇒ Object



114
115
116
117
# File 'lib/configuration.rb', line 114

def smtp(&block)
  Rails.application.config.action_mailer.smtp_settings = HashDsl.hash_from_block(block) if block_given?
  Rails.application.config.action_mailer.smtp_settings
end

#supports_pull_requests?Boolean

Returns:

  • (Boolean)


330
331
332
# File 'lib/configuration.rb', line 330

def supports_pull_requests?
  github[:organization].present?
end

#ticket_colorsObject



221
222
223
# File 'lib/configuration.rb', line 221

def ticket_colors
  @ticket_types
end

#ticket_types(*args) ⇒ Object



213
214
215
216
217
218
219
# File 'lib/configuration.rb', line 213

def ticket_types(*args)
  if args.any?
    @ticket_types = args.first
    @ticket_types.default = "EFEFEF"
  end
  @ticket_types.keys
end

#time_zone(*args) ⇒ Object



73
74
75
76
77
# File 'lib/configuration.rb', line 73

def time_zone(*args)
  return Rails.application.config.time_zone if args.none?
  Rails.application.config.time_zone = args.first
  Time.zone = args.first
end

#title(*args) ⇒ Object



63
64
65
66
# File 'lib/configuration.rb', line 63

def title(*args)
  @title = args.first if args.any?
  @title ||= "Houston"
end

#use(module_name, args = {}, &block) ⇒ Object

Modules



340
341
342
# File 'lib/configuration.rb', line 340

def use(module_name, args={}, &block)
  @modules << ::Houston::Module.new(module_name, args, &block)
end

#user_optionsObject



158
159
160
# File 'lib/configuration.rb', line 158

def user_options
  @user_options.values
end

#uses?(module_name) ⇒ Boolean

Returns:

  • (Boolean)


345
346
347
348
# File 'lib/configuration.rb', line 345

def uses?(module_name)
  module_name = module_name.to_s
  modules.any? { |mod| mod.name == module_name }
end

#validate!Object

Validation



432
433
434
435
436
437
438
439
440
441
# File 'lib/configuration.rb', line 432

def validate!
  raise MissingConfiguration, <<-ERROR unless mailer_sender

    Houston requires a default email address to be supplied for mailers
    You can set the address by adding the following line to config/config.rb:

      mailer_sender "[email protected]"

    ERROR
end