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.



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

def model_class
  @model_class
end

#model_not_foundObject

Returns the value of attribute model_not_found.



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

def model_not_found
  @model_not_found
end

#search_fieldObject

Returns the value of attribute search_field.



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

def search_field
  @search_field
end

Instance Method Details

#inherited(subclass) ⇒ Object



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

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



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

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