lib/upgrow/model.rb in upgrow-0.0.2 vs lib/upgrow/model.rb in upgrow-0.0.3
- old
+ new
@@ -1,7 +1,10 @@
# frozen_string_literal: true
+require_relative 'active_record_schema'
+require_relative 'basic_model'
+
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
@@ -14,22 +17,19 @@
#
# 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 < ImmutableObject
- attribute :id
- attribute :created_at
- attribute :updated_at
+ class Model < BasicModel
+ class << self
+ private
- # Initializes a new Model with the given member values.
- #
- # @param args [Hash<Symbol, Object>] the list of values for each attribute.
- #
- # @raise [KeyError] if an attribute is missing in the list of arguments.
- def initialize(**args)
- self.class.attribute_names.each { |key| args.fetch(key) }
+ def inherited(subclass)
+ super
- super
+ subclass.schema = ActiveRecordSchema.new(
+ subclass.name + 'Record', subclass.schema
+ )
+ end
end
end
end