lib/hanami/repository.rb in hanami-model-1.0.0 vs lib/hanami/repository.rb in hanami-model-1.0.1

- old
+ new

@@ -4,10 +4,11 @@ require 'hanami/model/mapped_relation' require 'hanami/model/associations/dsl' require 'hanami/model/association' require 'hanami/utils/class' require 'hanami/utils/class_attribute' +require 'hanami/utils/io' module Hanami # Mediates between the entities and the persistence layer, by offering an API # to query and execute commands on a database. # @@ -17,12 +18,11 @@ # `Repository` suffix to the entity class name. # # @example # require 'hanami/model' # - # class Article - # include Hanami::Entity + # class Article < Hanami::Entity # end # # # valid # class ArticleRepository < Hanami::Repository # end @@ -105,11 +105,11 @@ # @since 0.1.0 # # @see Hanami::Entity # @see http://martinfowler.com/eaaCatalog/repository.html # @see http://en.wikipedia.org/wiki/Dependency_inversion_principle - class Repository < ROM::Repository::Root + class Repository < ROM::Repository::Root # rubocop:disable Metrics/ClassLength # Plugins for database commands # # @since 0.7.0 # @api private # @@ -280,16 +280,25 @@ def self.inherited(klass) klass.class_eval do include Utils::ClassAttribute auto_struct true - class_attribute :entity + @associations = nil + @mapping = nil + @schema = nil + class_attribute :entity class_attribute :entity_name - self.entity_name = Model::EntityName.new(name) - class_attribute :relation - self.relation = Model::RelationName.new(name) + + Hanami::Utils::IO.silence_warnings do + def self.relation=(name) + @relation = name.to_sym + end + end + + self.entity_name = Model::EntityName.new(name) + self.relation = Model::RelationName.new(name) commands :create, update: :by_pk, delete: :by_pk, mapper: Model::MappedRelation.mapper_name, use: COMMAND_PLUGINS prepend Commands end