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.



27
28
29
# File 'lib/pathway/plugins/sequel_models.rb', line 27

def model_class
  @model_class
end

#model_not_foundObject

Returns the value of attribute model_not_found.



27
28
29
# File 'lib/pathway/plugins/sequel_models.rb', line 27

def model_not_found
  @model_not_found
end

#search_fieldObject

Returns the value of attribute search_field.



27
28
29
# File 'lib/pathway/plugins/sequel_models.rb', line 27

def search_field
  @search_field
end

Instance Method Details

#inherited(subclass) ⇒ Object



38
39
40
41
42
43
# File 'lib/pathway/plugins/sequel_models.rb', line 38

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



29
30
31
32
33
34
35
36
# File 'lib/pathway/plugins/sequel_models.rb', line 29

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