Module: Pathway::Plugins::SequelModels::ClassMethods

Defined in:
lib/pathway/plugins/sequel_models.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#model_classObject

Returns the value of attribute model_class.



51
52
53
# File 'lib/pathway/plugins/sequel_models.rb', line 51

def model_class
  @model_class
end

#model_not_foundObject

Returns the value of attribute model_not_found.



51
52
53
# File 'lib/pathway/plugins/sequel_models.rb', line 51

def model_not_found
  @model_not_found
end

#search_fieldObject

Returns the value of attribute search_field.



51
52
53
# File 'lib/pathway/plugins/sequel_models.rb', line 51

def search_field
  @search_field
end

Instance Method Details

#inherited(subclass) ⇒ Object



62
63
64
65
66
67
# File 'lib/pathway/plugins/sequel_models.rb', line 62

def inherited(subclass)
  super
  subclass.model_class     = model_class
  subclass.search_field    = search_field
  subclass.model_not_found = model_not_found
end

#model(model_class, search_by: model_class.primary_key, set_result_key: true, set_context_param: true, error_message: nil) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/pathway/plugins/sequel_models.rb', line 53

def model(model_class, search_by: model_class.primary_key, set_result_key: true, set_context_param: true, error_message: nil)
  self.model_class     = model_class
  self.search_field    = search_by
  self.result_key      = Inflector.underscore(Inflector.demodulize(model_class.name)).to_sym if set_result_key
  self.model_not_found = error_message || "#{Inflector.humanize(Inflector.underscore(Inflector.demodulize(model_class.name)))} not found".freeze

  self.context(result_key => Contextualizer::OPTIONAL) if set_result_key && set_context_param
end