Class: ObjectifiedEnvironments::EnvironmentBuilder
- Inherits:
-
Object
- Object
- ObjectifiedEnvironments::EnvironmentBuilder
- Defined in:
- lib/objectified_environments/environment_builder.rb
Instance Method Summary collapse
- #environment ⇒ Object
-
#initialize(data_provider) ⇒ EnvironmentBuilder
constructor
A new instance of EnvironmentBuilder.
Constructor Details
#initialize(data_provider) ⇒ EnvironmentBuilder
Returns a new instance of EnvironmentBuilder.
5 6 7 8 9 10 11 |
# File 'lib/objectified_environments/environment_builder.rb', line 5 def initialize(data_provider) @rails_env = normalize(data_provider.rails_env) @user_name = normalize(data_provider.user_name) @host_name = normalize(data_provider.host_name) raise ArgumentError, "@rails_env is required: #{rails_env.inspect}" unless @rails_env && @rails_env.strip.length > 0 end |
Instance Method Details
#environment ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/objectified_environments/environment_builder.rb', line 13 def environment candidate_names = [ ] candidate_names << class_name_for_candidate(@rails_env, @user_name, @host_name) if @user_name && @host_name candidate_names << class_name_for_candidate(@rails_env, nil, @host_name) if @host_name candidate_names << class_name_for_candidate(@rails_env, @user_name, @nil) if @user_name candidate_names << class_name_for_candidate(@rails_env, nil, nil) raise "This should be impossible: we should always have a candidate" unless candidate_names.length > 0 out = nil candidate_names.each do |candidate_name| klass = begin candidate_name.constantize rescue NameError nil end return instantiate_from_class(klass) if klass end no_environment_found!(candidate_names) end |