Module: Railsmith::BaseService::AssociationDsl::ClassMethods
- Defined in:
- lib/railsmith/base_service/association_dsl.rb
Overview
Class-level DSL macros for declaring associations on a service.
Instance Method Summary collapse
-
#association_registry ⇒ Object
Returns the AssociationRegistry for this class.
-
#belongs_to(name, service:, foreign_key: nil, optional: false) ⇒ Object
Declare a belongs_to association.
-
#has_many(name, service:, foreign_key: nil, dependent: :ignore, validate: true, async: false) ⇒ Object
Declare a has_many association.
-
#has_one(name, service:, foreign_key: nil, dependent: :ignore, validate: true, async: false) ⇒ Object
Declare a has_one association.
- #inherited(subclass) ⇒ Object
Instance Method Details
#association_registry ⇒ Object
Returns the AssociationRegistry for this class.
90 91 92 |
# File 'lib/railsmith/base_service/association_dsl.rb', line 90 def association_registry @association_registry ||= AssociationRegistry.new end |
#belongs_to(name, service:, foreign_key: nil, optional: false) ⇒ Object
Declare a belongs_to association.
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/railsmith/base_service/association_dsl.rb', line 78 def belongs_to(name, service:, foreign_key: nil, optional: false) association_registry.register( AssociationDefinition.new( name, :belongs_to, service: service, foreign_key: foreign_key, optional: optional ) ) end |
#has_many(name, service:, foreign_key: nil, dependent: :ignore, validate: true, async: false) ⇒ Object
Declare a has_many association.
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/railsmith/base_service/association_dsl.rb', line 36 def has_many(name, service:, foreign_key: nil, dependent: :ignore, validate: true, async: false) association_registry.register( AssociationDefinition.new( name, :has_many, service: service, foreign_key: foreign_key, dependent: dependent, validate: validate, async: async ) ) end |
#has_one(name, service:, foreign_key: nil, dependent: :ignore, validate: true, async: false) ⇒ Object
Declare a has_one association.
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/railsmith/base_service/association_dsl.rb', line 59 def has_one(name, service:, foreign_key: nil, dependent: :ignore, validate: true, async: false) association_registry.register( AssociationDefinition.new( name, :has_one, service: service, foreign_key: foreign_key, dependent: dependent, validate: validate, async: async ) ) end |
#inherited(subclass) ⇒ Object
94 95 96 97 |
# File 'lib/railsmith/base_service/association_dsl.rb', line 94 def inherited(subclass) super subclass.instance_variable_set(:@association_registry, association_registry.dup) end |