Module: Pathway::Plugins::SequelModels::InstanceMethods

Extended by:
Forwardable
Defined in:
lib/pathway/plugins/sequel_models.rb

Instance Method Summary collapse

Instance Method Details

#fetch_model(state, from: model_class, using: search_field, search_by: search_field, to: result_key, overwrite: false) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/pathway/plugins/sequel_models.rb', line 45

def fetch_model(state, from: model_class, using: search_field, search_by: search_field, to: result_key, overwrite: false)
  if state[to].nil? || overwrite
    find_model_with(state[:input][using], from, search_by)
      .then { |model| state.update(to => model) }
  else
    state
  end
end

#find_model_with(key, dataset = model_class, column = search_field) ⇒ Object



54
55
56
# File 'lib/pathway/plugins/sequel_models.rb', line 54

def find_model_with(key, dataset = model_class, column = search_field)
  wrap_if_present(dataset.first(column => key))
end