Class: Houston::Configuration
- Inherits:
-
Object
- Object
- Houston::Configuration
show all
- Defined in:
- lib/houston/boot/configuration.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#abilities(&block) ⇒ Object
-
#action(name, required_params = [], &block) ⇒ Object
-
#configure_abilities(context, user) ⇒ Object
-
#configure_team_abilities(context, teammate) ⇒ Object
-
#defines_abilities? ⇒ Boolean
-
#environments(*args) ⇒ Object
-
#every(*args, &block) ⇒ Object
-
#google_analytics(&block) ⇒ Object
-
#host(*args) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#load(glob) ⇒ Object
-
#mailer_from ⇒ Object
-
#mailer_sender(*args) ⇒ Object
-
#method_missing(name, *args, &block) ⇒ Object
-
#module(module_name) ⇒ Object
-
#navigation(*args) ⇒ Object
-
#oauth(provider_name, &block) ⇒ Object
-
#on(*args, &block) ⇒ Object
-
#parallelization(*args) ⇒ Object
-
#parallelize? ⇒ Boolean
-
#password_length(*args) ⇒ Object
-
#project_categories(*args) ⇒ Object
-
#project_colors(*args) ⇒ Object
-
#project_features(*args) ⇒ Object
-
#role(role_name, &abilities_block) ⇒ Object
-
#roles ⇒ Object
-
#root(*args) ⇒ Object
-
#s3(&block) ⇒ Object
-
#secret_key_base(*args) ⇒ Object
-
#smtp(&block) ⇒ Object
-
#time_zone(*args) ⇒ Object
-
#title(*args) ⇒ Object
-
#triggers ⇒ Object
-
#use(module_name, &block) ⇒ Object
-
#use_ssl(*args) ⇒ Object
-
#use_ssl? ⇒ Boolean
-
#uses?(module_name) ⇒ Boolean
-
#validate! ⇒ Object
Constructor Details
Returns a new instance of Configuration.
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/houston/boot/configuration.rb', line 25
def initialize
@root = Rails.root
@use_ssl = Rails.env.production?
@oauth_providers = []
@roles = Hash.new { |hash, key| hash[key] = [] }
@roles["Team Owner"].push(Proc.new do |team|
can :manage, team
can :manage, Project, team_id: team.id
end)
@modules = []
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
374
375
376
377
|
# File 'lib/houston/boot/configuration.rb', line 374
def method_missing(name, *args, &block)
puts "\e[31mMissing Configuration option: \e[1m#{name}\e[0;90m\n#{caller[0]}\e[0m\n\n"
nil
end
|
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
23
24
25
|
# File 'lib/houston/boot/configuration.rb', line 23
def actions
@actions
end
|
#modules ⇒ Object
Returns the value of attribute modules.
281
282
283
|
# File 'lib/houston/boot/configuration.rb', line 281
def modules
@modules
end
|
#oauth_providers ⇒ Object
Returns the value of attribute oauth_providers.
23
24
25
|
# File 'lib/houston/boot/configuration.rb', line 23
def oauth_providers
@oauth_providers
end
|
#observer ⇒ Object
Returns the value of attribute observer.
23
24
25
|
# File 'lib/houston/boot/configuration.rb', line 23
def observer
@observer
end
|
#timer ⇒ Object
Returns the value of attribute timer.
23
24
25
|
# File 'lib/houston/boot/configuration.rb', line 23
def timer
@timer
end
|
Instance Method Details
#abilities(&block) ⇒ Object
244
245
246
|
# File 'lib/houston/boot/configuration.rb', line 244
def abilities(&block)
@abilities_block = block
end
|
#action(name, required_params = [], &block) ⇒ Object
299
300
301
|
# File 'lib/houston/boot/configuration.rb', line 299
def action(name, required_params=[], &block)
actions.define(name, required_params, &block)
end
|
252
253
254
|
# File 'lib/houston/boot/configuration.rb', line 252
def configure_abilities(context, user)
context.instance_exec(user, &@abilities_block)
end
|
256
257
258
259
260
261
262
263
|
# File 'lib/houston/boot/configuration.rb', line 256
def configure_team_abilities(context, teammate)
teammate.roles.each do |role|
context.can :read, teammate.team
@roles.fetch(role).each do |abilities_block|
context.instance_exec(teammate.team, &abilities_block)
end
end
end
|
#defines_abilities? ⇒ Boolean
248
249
250
|
# File 'lib/houston/boot/configuration.rb', line 248
def defines_abilities?
@abilities_block.present?
end
|
#environments(*args) ⇒ Object
225
226
227
228
|
# File 'lib/houston/boot/configuration.rb', line 225
def environments(*args)
@environments = args if args.any?
@environments ||= []
end
|
#every(*args, &block) ⇒ Object
319
320
321
322
323
324
325
|
# File 'lib/houston/boot/configuration.rb', line 319
def every(*args, &block)
interval, action_name = extract_trigger_and_action!(args)
action = assert_action! action_name, &block
action.assert_required_params! []
triggers.every interval, action_name
action
end
|
#google_analytics(&block) ⇒ Object
158
159
160
161
|
# File 'lib/houston/boot/configuration.rb', line 158
def google_analytics(&block)
@google_analytics = HashDsl.hash_from_block(block) if block_given?
@google_analytics ||= {}
end
|
#host(*args) ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/houston/boot/configuration.rb', line 107
def host(*args)
if args.any?
@host = args.first
if Rails.env.production?
Houston::Application.config.action_cable.mount_path = nil
Houston::Application.config.action_cable.url = "wss://#{host}:4200"
Houston::Application.config.action_cable.allowed_request_origins = %w{http https}
.map { |protocol| "#{protocol}://#{host}" }
end
end
@host ||= nil
end
|
#load(glob) ⇒ Object
350
351
352
353
354
355
356
357
|
# File 'lib/houston/boot/configuration.rb', line 350
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_from ⇒ Object
149
150
151
152
153
154
155
156
|
# File 'lib/houston/boot/configuration.rb', line 149
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
141
142
143
144
145
146
147
|
# File 'lib/houston/boot/configuration.rb', line 141
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
288
289
290
291
|
# File 'lib/houston/boot/configuration.rb', line 288
def module(module_name)
module_name = module_name.to_s
modules.detect { |mod| mod.name == module_name }
end
|
#navigation(*args) ⇒ Object
205
206
207
208
209
|
# File 'lib/houston/boot/configuration.rb', line 205
def navigation(*args)
@navigation = args if args.any?
return Houston.navigation.slugs unless @navigation
@navigation & Houston.navigation.slugs
end
|
#oauth(provider_name, &block) ⇒ Object
187
188
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/houston/boot/configuration.rb', line 187
def oauth(provider_name, &block)
settings = HashDsl.hash_from_block(block)
provider = Houston.oauth.get_provider(provider_name)
raise ArgumentError, "Provider must define a client_id" if settings[:client_id].blank?
raise ArgumentError, "Provider must define a client_secret" if settings[:client_secret].blank?
provider.client_id = settings[:client_id]
provider.client_secret = settings[:client_secret]
@oauth_providers << provider_name.to_s
end
|
#on(*args, &block) ⇒ Object
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
# File 'lib/houston/boot/configuration.rb', line 303
def on(*args, &block)
event_name, action_name = extract_trigger_and_action!(args)
event = Houston.events[event_name]
unless event
puts "\e[31mUnregistered event: \e[1m#{event_name}\e[0;90m\n#{caller[0]}\e[0m\n\n"
return
end
action = assert_action! action_name, event.params, &block
action.assert_required_params! event.params
triggers.on event_name, action_name
action
end
|
#parallelization(*args) ⇒ Object
168
169
170
171
|
# File 'lib/houston/boot/configuration.rb', line 168
def parallelization(*args)
@parallelization = args.first if args.any?
@parallelization ||= :off
end
|
#parallelize? ⇒ Boolean
173
174
175
|
# File 'lib/houston/boot/configuration.rb', line 173
def parallelize?
parallelization == :on
end
|
#password_length(*args) ⇒ Object
163
164
165
166
|
# File 'lib/houston/boot/configuration.rb', line 163
def password_length(*args)
@password_length = args.first if args.any?
@password_length ||= 8..128
end
|
#project_categories(*args) ⇒ Object
200
201
202
203
|
# File 'lib/houston/boot/configuration.rb', line 200
def project_categories(*args)
@project_categories = args if args.any?
@project_categories ||= []
end
|
#project_colors(*args) ⇒ Object
219
220
221
222
223
|
# File 'lib/houston/boot/configuration.rb', line 219
def project_colors(*args)
new_hash = Hash.new(ColorValue.new("default", "505050"))
@project_colors = args.first.each_with_object(new_hash) { |(key, hex), hash| hash[key] = ColorValue.new(key, hex) } if args.any?
@project_colors ||= new_hash
end
|
#project_features(*args) ⇒ Object
211
212
213
214
215
|
# File 'lib/houston/boot/configuration.rb', line 211
def project_features(*args)
@project_features = args if args.any?
return Houston.project_features.all unless @project_features
@project_features & Houston.project_features.all
end
|
#role(role_name, &abilities_block) ⇒ Object
234
235
236
|
# File 'lib/houston/boot/configuration.rb', line 234
def role(role_name, &abilities_block)
@roles[role_name].push abilities_block
end
|
#roles ⇒ Object
230
231
232
|
# File 'lib/houston/boot/configuration.rb', line 230
def roles
@roles.keys
end
|
#root(*args) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/houston/boot/configuration.rb', line 62
def root(*args)
if args.any?
@root = args.first
ActiveRecord::Tasks::DatabaseTasks.db_dir = root.join("db")
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")
cable_config = Houston.root.join("config/cable.yml")
if File.exists?(cable_config)
ActiveSupport.on_load(:action_cable) do
Houston::Application.paths["config/cable"] = cable_config
ActionCable.server.config.cable = Rails.application.config_for(cable_config).with_indifferent_access
end
ActionCable.server.config.cable = Rails.application.config_for(cable_config).with_indifferent_access
else
Rails.application.config.before_initialize do
Rails.logger.warn "\e[33m[boot] \e[93m#{cable_config}\e[33m does not exist: you will not be able to use Houston.observer on the client\e[0m"
end
end
end
@root
end
|
#s3(&block) ⇒ Object
182
183
184
185
|
# File 'lib/houston/boot/configuration.rb', line 182
def s3(&block)
@s3 = HashDsl.hash_from_block(block) if block_given?
@s3 ||= {}
end
|
#secret_key_base(*args) ⇒ Object
130
131
132
133
|
# File 'lib/houston/boot/configuration.rb', line 130
def secret_key_base(*args)
return Houston::Application.config.secret_key_base if args.none?
Houston::Application.config.secret_key_base = args.first
end
|
#smtp(&block) ⇒ Object
177
178
179
180
|
# File 'lib/houston/boot/configuration.rb', line 177
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
|
#time_zone(*args) ⇒ Object
135
136
137
138
139
|
# File 'lib/houston/boot/configuration.rb', line 135
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
102
103
104
105
|
# File 'lib/houston/boot/configuration.rb', line 102
def title(*args)
@title = args.first if args.any?
@title ||= "Houston"
end
|
#triggers ⇒ Object
37
38
39
40
|
# File 'lib/houston/boot/configuration.rb', line 37
def triggers
return @triggers if defined?(@triggers)
@triggers = Houston::Triggers.new(self)
end
|
#use(module_name, &block) ⇒ Object
271
272
273
274
275
276
277
278
279
280
|
# File 'lib/houston/boot/configuration.rb', line 271
def use(module_name, &block)
mod = self.module(module_name)
mod ||= ::Houston::Module.new(module_name).tap { |mod| @modules << mod }
if mod.accepts_configuration?
mod.load_configuration(block)
else raise ArgumentError, "#{module_name} does not accept configuration"
end if block_given?
mod.dependencies.each(&method(:use))
mod
end
|
#use_ssl(*args) ⇒ Object
121
122
123
124
|
# File 'lib/houston/boot/configuration.rb', line 121
def use_ssl(*args)
@use_ssl = args.first if args.any?
@use_ssl
end
|
#use_ssl? ⇒ Boolean
126
127
128
|
# File 'lib/houston/boot/configuration.rb', line 126
def use_ssl?
@use_ssl
end
|
#uses?(module_name) ⇒ Boolean
283
284
285
286
|
# File 'lib/houston/boot/configuration.rb', line 283
def uses?(module_name)
module_name = module_name.to_s
modules.any? { |mod| mod.name == module_name }
end
|
#validate! ⇒ Object
363
364
365
366
367
368
369
370
371
372
|
# File 'lib/houston/boot/configuration.rb', line 363
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
|