Sha256: 6d3a7626f638467d843c0974be5c12929b78855e9ba3027eb39b6aec3520f6ff
Contents?: true
Size: 1.45 KB
Versions: 3
Compression:
Stored size: 1.45 KB
Contents
module Katello module Util module Model # hardcoded model names (uses kp_ prefix) def self.table_to_model_hash { "kt_environment" => "KTEnvironment", } end # convert Rails Model name to Class or nil when no such table name exists def self.table_to_class(name) class_name = table_to_model_hash[name] || name.classify class_name.constantize rescue NameError # constantize throws NameError return nil end def self.labelize(name) if name (name.ascii_only? && name.length <= 128) ? name.gsub(/[^a-z0-9\-_]+/i, "_") : uuid end end def self.uuid SecureRandom.uuid end def self.controller_path_to_model_hash { "katello/environments" => "Katello::KTEnvironment", } end def self.controller_path_to_model(controller) if controller_path_to_model_hash.key? controller.to_s controller_path_to_model_hash[controller.to_s].constantize else controller.to_s.classify.constantize end end def self.model_to_controller_path_hash controller_path_to_model_hash.invert end def self.model_to_controller_path(model) if model_to_controller_path_hash.key? model.to_s model_to_controller_path_hash[model.to_s] else model.to_s.underscore.pluralize end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
katello-4.15.0 | app/lib/katello/util/model.rb |
katello-4.15.0.rc2 | app/lib/katello/util/model.rb |
katello-4.15.0.rc1 | app/lib/katello/util/model.rb |