module Resta::Model

Mixins for subclass for ‘Sequel::Model`.

Constants

COMMON_DATABASE_FIELDS

Public Class Methods

included(receiver) click to toggle source
# File lib/resta/model.rb, line 54
def self.included(receiver)
  raise UnsupportedClassError.new(
    "#{receiver.class.name} is not a subclass of Sequel::Model"
  ) unless receiver < Sequel::Model
  necessary_fields_checker receiver
  receiver.extend ClassMethods
  receiver.send :include, InstanceMethods
end

Private Class Methods

necessary_fields_checker(receiver) click to toggle source
# File lib/resta/model.rb, line 63
def self.necessary_fields_checker(receiver)
  COMMON_DATABASE_FIELDS.each_pair do |field, type|
    raise NecessaryFieldMissingError.new(
      "Missing field `#{field}`##{type} in #{receiver.table_name}"
    ) unless(receiver.db_schema.has_key?(field) &&
             receiver.db_schema[field][:type] == type)
  end
end