Module: Katello::Util::Model
- Defined in:
- app/lib/katello/util/model.rb
Class Method Summary collapse
- .controller_path_to_model(controller) ⇒ Object
- .controller_path_to_model_hash ⇒ Object
- .labelize(name) ⇒ Object
- .model_to_controller_path(model) ⇒ Object
- .model_to_controller_path_hash ⇒ Object
-
.table_to_class(name) ⇒ Object
convert Rails Model name to Class or nil when no such table name exists.
-
.table_to_model_hash ⇒ Object
hardcoded model names (uses kp_ prefix).
- .uuid ⇒ Object
Class Method Details
.controller_path_to_model(controller) ⇒ Object
37 38 39 40 41 42 43 |
# File 'app/lib/katello/util/model.rb', line 37 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 |
.controller_path_to_model_hash ⇒ Object
30 31 32 33 34 35 |
# File 'app/lib/katello/util/model.rb', line 30 def self.controller_path_to_model_hash { "katello/environments" => "Katello::KTEnvironment", "katello/content_hosts" => "Katello::System" } end |
.labelize(name) ⇒ Object
20 21 22 23 24 |
# File 'app/lib/katello/util/model.rb', line 20 def self.labelize(name) if name (name.ascii_only? && name.length <= 128) ? name.gsub(/[^a-z0-9\-_]/i, "_") : uuid end end |
.model_to_controller_path(model) ⇒ Object
49 50 51 52 53 54 55 |
# File 'app/lib/katello/util/model.rb', line 49 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 |
.model_to_controller_path_hash ⇒ Object
45 46 47 |
# File 'app/lib/katello/util/model.rb', line 45 def self.model_to_controller_path_hash controller_path_to_model_hash.invert end |
.table_to_class(name) ⇒ Object
convert Rails Model name to Class or nil when no such table name exists
12 13 14 15 16 17 18 |
# File 'app/lib/katello/util/model.rb', line 12 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 |
.table_to_model_hash ⇒ Object
hardcoded model names (uses kp_ prefix)
5 6 7 8 9 |
# File 'app/lib/katello/util/model.rb', line 5 def self.table_to_model_hash { "kt_environment" => "KTEnvironment" } end |
.uuid ⇒ Object
26 27 28 |
# File 'app/lib/katello/util/model.rb', line 26 def self.uuid SecureRandom.uuid end |