Module: Sunrise::Utils
- Defined in:
- lib/sunrise/utils.rb,
lib/sunrise/utils/csv_document.rb,
lib/sunrise/utils/eval_helpers.rb,
lib/sunrise/utils/search_wrapper.rb
Defined Under Namespace
Modules: EvalHelpers, SearchWrapper Classes: CsvDocument
Constant Summary collapse
- IMAGE_TYPES =
['image/jpeg', 'image/png', 'image/gif', 'image/jpg', 'image/pjpeg', 'image/tiff', 'image/x-png'].freeze
Class Method Summary collapse
- .get_model(model_name, *args) ⇒ Object
-
.lookup(model_name, _klass = nil) ⇒ Object
Given a string
model_name, finds the corresponding model class. -
.normalize_friendly_id(input) ⇒ Object
Convert input to friendly slug using babosa gem.
-
.sort_to_hash(value) ⇒ Object
Convert sort string to hash "create_at_desc" to { :column => "created_at", :mode => "desc" }.
- .superclasses(klass) ⇒ Object
Class Method Details
.get_model(model_name, *args) ⇒ Object
12 13 14 15 |
# File 'lib/sunrise/utils.rb', line 12 def self.get_model(model_name, *args) klass = lookup(['Sunrise', model_name.to_s.classify].join, Sunrise::AbstractModel) klass ? klass.new(*args) : nil end |
.lookup(model_name, _klass = nil) ⇒ Object
Given a string model_name, finds the corresponding model class
18 19 20 21 22 23 24 25 |
# File 'lib/sunrise/utils.rb', line 18 def self.lookup(model_name, _klass = nil) model = model_name.constantize model if model&.is_a?(Class) rescue LoadError, NameError Rails.logger.error "Error while loading '#{model_name}': #{$!}" nil end |
.normalize_friendly_id(input) ⇒ Object
Convert input to friendly slug using babosa gem
49 50 51 |
# File 'lib/sunrise/utils.rb', line 49 def self.normalize_friendly_id(input) input.to_s.parameterize end |
.sort_to_hash(value) ⇒ Object
Convert sort string to hash "create_at_desc" to { :column => "created_at", :mode => "desc" }
39 40 41 42 43 44 45 |
# File 'lib/sunrise/utils.rb', line 39 def self.sort_to_hash(value) items = value.split('_') mode = items.pop column = items.join('_') { column: column, mode: mode } end |
.superclasses(klass) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/sunrise/utils.rb', line 27 def self.superclasses(klass) superclasses = [] while klass superclasses << klass.superclass if klass&.superclass klass = klass.superclass end superclasses end |