Sha256: c84a059a8f7fad9696ee3a760756458d08eb1923667c83c0259676e68b3a16f5

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

require_relative 'active_record_schema'
require_relative 'basic_model'
require_relative 'naming'

module Upgrow
  # Models are objects that represent core entities of the app's business logic.
  # These are usually persisted and can be fetched and created as needed. They
  # have unique keys for identification (usually a numeric value), and, most
  # importantly perhaps, they are immutable. This is the key difference between
  # this new Model layer of objects and the Active Record instances regularly
  # referred to as models in typical Rails default apps.
  #
  # Another difference between Models and Records is that, once instantiated,
  # Models simply hold its attributes immutably, and they don't have any
  # capabilities to create or update any information in the persistence layer.
  #
  # The collaboration between Repositories and Models is what allows Active
  # Record to be completely hidden away from any other areas of the app. There
  # are no references to Records in controllers, views, and anywhere else.
  # Repositories are invoked instead, which in turn return read-only Models.
  class Model < BasicModel
    class << self
      private

      def inherited(subclass)
        super

        subclass.schema = ActiveRecordSchema.new(
          Naming.model_to_record(subclass.name), subclass.schema
        )
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
upgrow-0.0.5 lib/upgrow/model.rb