Module: Wallaby::Utils
- Defined in:
- lib/utils/wallaby/utils.rb
Class Method Summary collapse
- .to_hash(array) ⇒ Object
- .to_model_class(resources_name, source = nil) ⇒ Object
- .to_model_label(model_class) ⇒ Object
- .to_model_name(resources_name) ⇒ Object
- .to_resources_name(model_class) ⇒ Object
Class Method Details
.to_hash(array) ⇒ Object
28 29 30 |
# File 'lib/utils/wallaby/utils.rb', line 28 def self.to_hash(array) Hash[ *array.flatten(1) ] end |
.to_model_class(resources_name, source = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/utils/wallaby/utils.rb', line 17 def self.to_model_class(resources_name, source = nil) return if resources_name.blank? begin class_name = to_model_name resources_name class_name.constantize rescue = [ class_name, source ].compact.join(' from ') fail Wallaby::ModelNotFound, end end |
.to_model_label(model_class) ⇒ Object
7 8 9 10 |
# File 'lib/utils/wallaby/utils.rb', line 7 def self.to_model_label(model_class) model_class_name = to_model_name model_class model_class_name.titleize.gsub '/', ' / ' end |
.to_model_name(resources_name) ⇒ Object
12 13 14 15 |
# File 'lib/utils/wallaby/utils.rb', line 12 def self.to_model_name(resources_name) return '' if resources_name.blank? resources_name.to_s.singularize.gsub('::', '/').camelize end |
.to_resources_name(model_class) ⇒ Object
2 3 4 5 |
# File 'lib/utils/wallaby/utils.rb', line 2 def self.to_resources_name(model_class) return '' if model_class.blank? model_class.to_s.underscore.gsub('/', '::').pluralize end |