Class: Houston::Configuration
- Inherits:
-
Object
- Object
- Houston::Configuration
- Defined in:
- lib/houston/boot/configuration.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#authentication_strategy_configuration ⇒ Object
readonly
Returns the value of attribute authentication_strategy_configuration.
-
#modules ⇒ Object
readonly
Returns the value of attribute modules.
-
#observer ⇒ Object
readonly
Returns the value of attribute observer.
-
#timer ⇒ Object
readonly
Returns the value of attribute timer.
Instance Method Summary collapse
-
#abilities(&block) ⇒ Object
Permissions.
-
#action(name, required_params = [], &block) ⇒ Object
Actions and Triggers.
-
#at(*args, &block) ⇒ Object
DEPRECATED.
-
#authentication_strategy(strategy = nil, &block) ⇒ Object
Authentication options.
- #configure_abilities(context, user) ⇒ Object
- #configure_team_abilities(context, teammate) ⇒ Object
- #defines_abilities? ⇒ Boolean
- #devise_configuration ⇒ Object
- #environments(*args) ⇒ Object
- #every(*args, &block) ⇒ Object
- #google_analytics(&block) ⇒ Object
- #host(*args) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #keypair ⇒ Object
- #load(glob) ⇒ Object
- #mailer_from ⇒ Object
- #mailer_sender(*args) ⇒ Object
- #method_missing(name, *args, &block) ⇒ Object
- #module(module_name) ⇒ Object
- #navigation(*args) ⇒ Object
- #on(*args, &block) ⇒ Object
- #parallelization(*args) ⇒ Object
- #parallelize? ⇒ Boolean
- #passphrase(*args) ⇒ Object
- #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
Global configuration.
- #s3(&block) ⇒ Object
- #smtp(&block) ⇒ Object
- #time_zone(*args) ⇒ Object
- #title(*args) ⇒ Object
- #triggers ⇒ Object
-
#use(module_name, &block) ⇒ Object
Modules.
- #uses?(module_name) ⇒ Boolean
-
#validate! ⇒ Object
Validation.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/houston/boot/configuration.rb', line 24 def initialize @root = Rails.root @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 = [] @authentication_strategy = :database @authentication_strategy_configuration = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
447 448 449 450 |
# File 'lib/houston/boot/configuration.rb', line 447 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 (readonly)
Returns the value of attribute actions.
22 23 24 |
# File 'lib/houston/boot/configuration.rb', line 22 def actions @actions end |
#authentication_strategy_configuration ⇒ Object (readonly)
Returns the value of attribute authentication_strategy_configuration.
240 241 242 |
# File 'lib/houston/boot/configuration.rb', line 240 def authentication_strategy_configuration @authentication_strategy_configuration end |
#modules ⇒ Object (readonly)
Returns the value of attribute modules.
306 307 308 |
# File 'lib/houston/boot/configuration.rb', line 306 def modules @modules end |
#observer ⇒ Object (readonly)
Returns the value of attribute observer.
22 23 24 |
# File 'lib/houston/boot/configuration.rb', line 22 def observer @observer end |
#timer ⇒ Object (readonly)
Returns the value of attribute timer.
22 23 24 |
# File 'lib/houston/boot/configuration.rb', line 22 def timer @timer end |
Instance Method Details
#abilities(&block) ⇒ Object
Permissions
269 270 271 |
# File 'lib/houston/boot/configuration.rb', line 269 def abilities(&block) @abilities_block = block end |
#action(name, required_params = [], &block) ⇒ Object
Actions and Triggers
324 325 326 |
# File 'lib/houston/boot/configuration.rb', line 324 def action(name, required_params=[], &block) actions.define(name, required_params, &block) end |
#at(*args, &block) ⇒ Object
DEPRECATED
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
# File 'lib/houston/boot/configuration.rb', line 345 def at(*args, &block) time, action_name = extract_trigger_and_action!(args) action = assert_action! action_name, &block action.assert_required_params! [] # Passing options to Houston.config.at is deprecated # -------------------------------------------------------------- # if args.first.is_a?(Hash) = args.first if days_of_the_week = .delete(:every) Houston.deprecation_notice "Instead of passing every: #{days_of_the_week.inspect} to Houston.config.at, use Houston.config.at [#{days_of_the_week.inspect}, #{time}], ..." time = [days_of_the_week, time] end .keys.each do |key| Houston.deprecation_notice "#{key.inspect} is an unknown option for Houston.config.at. In the next version of houston-core, Houston.config.at will no longer accept options" end end # -------------------------------------------------------------- # # Houston.config.at is deprecated # -------------------------------------------------------------- # value = time wdays, time = value.is_a?(Array) ? value : [:day, value] interval = "#{wdays} at #{time}" Houston.deprecation_notice "Houston.config.at(#{value.inspect}) is deprecated; use Houston.config.every(#{interval.inspect}) instead" # -------------------------------------------------------------- # triggers.every interval, action_name action end |
#authentication_strategy(strategy = nil, &block) ⇒ Object
Authentication options
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/houston/boot/configuration.rb', line 225 def authentication_strategy(strategy=nil, &block) @authentication_strategy = strategy if strategy if block_given? @authentication_strategy_configuration = HashDsl.hash_from_block(block) if authentication_strategy == :ldap i{host port base field username_builder}.each do |required_field| next if @authentication_strategy_configuration.key?(required_field) raise "#{required_field} is a required field for :ldap authentication" end end end @authentication_strategy end |
#configure_abilities(context, user) ⇒ Object
277 278 279 |
# File 'lib/houston/boot/configuration.rb', line 277 def configure_abilities(context, user) context.instance_exec(user, &@abilities_block) end |
#configure_team_abilities(context, teammate) ⇒ Object
281 282 283 284 285 286 287 288 |
# File 'lib/houston/boot/configuration.rb', line 281 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
273 274 275 |
# File 'lib/houston/boot/configuration.rb', line 273 def defines_abilities? @abilities_block.present? end |
#devise_configuration ⇒ Object
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/houston/boot/configuration.rb', line 242 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 |
#environments(*args) ⇒ Object
206 207 208 209 |
# File 'lib/houston/boot/configuration.rb', line 206 def environments(*args) @environments = args if args.any? @environments ||= [] end |
#every(*args, &block) ⇒ Object
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
# File 'lib/houston/boot/configuration.rb', line 376 def every(*args, &block) interval, action_name = extract_trigger_and_action!(args) action = assert_action! action_name, &block action.assert_required_params! [] # Passing options to Houston.config.every is deprecated # -------------------------------------------------------------- # if args.first.is_a?(Hash) = args.first .keys.each do |key| Houston.deprecation_notice "#{key.inspect} is an unknown option for Houston.config.at. In the next version of houston-core, Houston.config.at will no longer accept options" end end # -------------------------------------------------------------- # triggers.every interval, action_name action end |
#google_analytics(&block) ⇒ Object
143 144 145 146 |
# File 'lib/houston/boot/configuration.rb', line 143 def google_analytics(&block) @google_analytics = HashDsl.hash_from_block(block) if block_given? @google_analytics ||= {} end |
#host(*args) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/houston/boot/configuration.rb', line 106 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 |
#keypair ⇒ Object
158 159 160 |
# File 'lib/houston/boot/configuration.rb', line 158 def keypair root.join("config", "keypair.pem") end |
#load(glob) ⇒ Object
423 424 425 426 427 428 429 430 |
# File 'lib/houston/boot/configuration.rb', line 423 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
134 135 136 137 138 139 140 141 |
# File 'lib/houston/boot/configuration.rb', line 134 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
126 127 128 129 130 131 132 |
# File 'lib/houston/boot/configuration.rb', line 126 def mailer_sender(*args) if args.any? @mailer_sender = args.first (Rails.application.config.action_mailer. ||= {}).merge!(from: @mailer_sender) end @mailer_sender ||= nil end |
#module(module_name) ⇒ Object
313 314 315 316 |
# File 'lib/houston/boot/configuration.rb', line 313 def module(module_name) module_name = module_name.to_s modules.detect { |mod| mod.name == module_name } end |
#navigation(*args) ⇒ Object
186 187 188 189 190 |
# File 'lib/houston/boot/configuration.rb', line 186 def (*args) = args if args.any? return Houston. unless & Houston. end |
#on(*args, &block) ⇒ Object
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/houston/boot/configuration.rb', line 328 def on(*args, &block) event_name, action_name = extract_trigger_and_action!(args) event = Houston.get_registered_event(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
162 163 164 165 |
# File 'lib/houston/boot/configuration.rb', line 162 def parallelization(*args) @parallelization = args.first if args.any? @parallelization ||= :off end |
#parallelize? ⇒ Boolean
167 168 169 |
# File 'lib/houston/boot/configuration.rb', line 167 def parallelize? parallelization == :on end |
#passphrase(*args) ⇒ Object
153 154 155 156 |
# File 'lib/houston/boot/configuration.rb', line 153 def passphrase(*args) @passphrase = args.first if args.any? @passphrase ||= nil end |
#password_length(*args) ⇒ Object
148 149 150 151 |
# File 'lib/houston/boot/configuration.rb', line 148 def password_length(*args) @password_length = args.first if args.any? @password_length ||= 8..128 end |
#project_categories(*args) ⇒ Object
181 182 183 184 |
# File 'lib/houston/boot/configuration.rb', line 181 def project_categories(*args) @project_categories = args if args.any? @project_categories ||= [] end |
#project_colors(*args) ⇒ Object
200 201 202 203 204 |
# File 'lib/houston/boot/configuration.rb', line 200 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
192 193 194 195 196 |
# File 'lib/houston/boot/configuration.rb', line 192 def project_features(*args) @project_features = args if args.any? return Houston.available_project_features unless @project_features @project_features & Houston.available_project_features end |
#role(role_name, &abilities_block) ⇒ Object
215 216 217 |
# File 'lib/houston/boot/configuration.rb', line 215 def role(role_name, &abilities_block) @roles[role_name].push abilities_block end |
#roles ⇒ Object
211 212 213 |
# File 'lib/houston/boot/configuration.rb', line 211 def roles @roles.keys end |
#root(*args) ⇒ Object
Global configuration
61 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 |
# File 'lib/houston/boot/configuration.rb', line 61 def root(*args) if args.any? @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") # ActionCable sets the default path for its config file # later on during initialization. We need to override the # path just before ActionCable is initialized. 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 # Make sure that we've loaded the Instance's config file # c.f. https://github.com/rails/rails/blob/v5.0.0.1/actioncable/lib/action_cable/engine.rb#L31 ActionCable.server.config.cable = Rails.application.config_for(cable_config).with_indifferent_access end # Make sure that we've loaded the Instance's config file # c.f. https://github.com/rails/rails/blob/v5.0.0.1/actioncable/lib/action_cable/engine.rb#L31 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
176 177 178 179 |
# File 'lib/houston/boot/configuration.rb', line 176 def s3(&block) @s3 = HashDsl.hash_from_block(block) if block_given? @s3 ||= {} end |
#smtp(&block) ⇒ Object
171 172 173 174 |
# File 'lib/houston/boot/configuration.rb', line 171 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
120 121 122 123 124 |
# File 'lib/houston/boot/configuration.rb', line 120 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
101 102 103 104 |
# File 'lib/houston/boot/configuration.rb', line 101 def title(*args) @title = args.first if args.any? @title ||= "Houston" end |
#triggers ⇒ Object
36 37 38 39 |
# File 'lib/houston/boot/configuration.rb', line 36 def triggers return @triggers if defined?(@triggers) @triggers = Houston::Triggers.new(self) end |
#use(module_name, &block) ⇒ Object
Modules
296 297 298 299 300 301 302 303 304 305 |
# File 'lib/houston/boot/configuration.rb', line 296 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 |
#uses?(module_name) ⇒ Boolean
308 309 310 311 |
# File 'lib/houston/boot/configuration.rb', line 308 def uses?(module_name) module_name = module_name.to_s modules.any? { |mod| mod.name == module_name } end |
#validate! ⇒ Object
Validation
436 437 438 439 440 441 442 443 444 445 |
# File 'lib/houston/boot/configuration.rb', line 436 def validate! raise MissingConfiguration, "\n Houston requires a default email address to be supplied for mailers\n You can set the address by adding the following line to config/config.rb:\n\n mailer_sender \"[email protected]\"\n\n ERROR\nend\n" unless mailer_sender |