Module: Katello::Concerns::EnvironmentExtensions::ClassMethods
- Defined in:
- app/models/katello/concerns/environment_extensions.rb
Instance Method Summary collapse
- #build_by_katello_id(org, env, content_view) ⇒ Object
- #construct_katello_id(org, env, content_view) ⇒ Object
-
#construct_name(org, env, content_view) ⇒ Object
content_view_id provides the uniqueness of the name.
- #find_by_katello_id(org, env, content_view) ⇒ Object
- #find_or_build_by_katello_id(org, env, content_view) ⇒ Object
Instance Method Details
#build_by_katello_id(org, env, content_view) ⇒ Object
38 39 40 41 42 43 44 |
# File 'app/models/katello/concerns/environment_extensions.rb', line 38 def build_by_katello_id(org, env, content_view) env_name = Environment.construct_name(org, env, content_view) katello_id = Environment.construct_katello_id(org, env, content_view) environment = Environment.new(:name => env_name, :organization_ids => [org.id], :location_ids => [::Location.default_location.id]) environment.katello_id = katello_id environment end |
#construct_katello_id(org, env, content_view) ⇒ Object
51 52 53 54 55 |
# File 'app/models/katello/concerns/environment_extensions.rb', line 51 def construct_katello_id(org, env, content_view) fail ArgumentError, "org has to be specified" if org.nil? fail ArgumentError, "env has to be specified" if env.nil? [org.label, env.label, content_view.label].reject(&:blank?).join('/') end |
#construct_name(org, env, content_view) ⇒ Object
content_view_id provides the uniqueness of the name
58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/katello/concerns/environment_extensions.rb', line 58 def construct_name(org, env, content_view) name = ["KT", org.try(:label), env.try(:label), content_view.try(:label), content_view.try(:id) ].reject(&:blank?).join('_') return name.tr('-', '_') end |
#find_by_katello_id(org, env, content_view) ⇒ Object
33 34 35 36 |
# File 'app/models/katello/concerns/environment_extensions.rb', line 33 def find_by_katello_id(org, env, content_view) katello_id = Environment.construct_katello_id(org, env, content_view) Environment.where(:katello_id => katello_id).first end |
#find_or_build_by_katello_id(org, env, content_view) ⇒ Object
46 47 48 49 |
# File 'app/models/katello/concerns/environment_extensions.rb', line 46 def find_or_build_by_katello_id(org, env, content_view) Environment.find_by_katello_id(org, env, content_view) || Environment.build_by_katello_id(org, env, content_view) end |