Module: Pathway::Plugins::SequelModels::InstanceMethods
- Extended by:
- Forwardable
- Defined in:
- lib/pathway/plugins/sequel_models.rb
Instance Method Summary collapse
- #fetch_model(state, from: model_class, search_by: search_field, using: search_by, to: result_key, overwrite: false, error_message: nil) ⇒ Object
- #find_model_with(key, dataset = model_class, column = search_field, error_message = nil) ⇒ Object
Instance Method Details
#fetch_model(state, from: model_class, search_by: search_field, using: search_by, to: result_key, overwrite: false, error_message: nil) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/pathway/plugins/sequel_models.rb', line 51 def fetch_model(state, from: model_class, search_by: search_field, using: search_by, to: result_key, overwrite: false, error_message: nil) ||= if from != model_class Inflector.humanize(Inflector.underscore(Inflector.demodulize(from.name))) + ' not found' else model_not_found end if state[to].nil? || overwrite wrap_if_present(state[:input][using], message: ) .then { |key| find_model_with(key, from, search_by, ) } .then { |model| state.update(to => model) } else state end end |
#find_model_with(key, dataset = model_class, column = search_field, error_message = nil) ⇒ Object
67 68 69 |
# File 'lib/pathway/plugins/sequel_models.rb', line 67 def find_model_with(key, dataset = model_class, column = search_field, = nil) wrap_if_present(dataset.first(column => key), message: ) end |